Question

This code gives me Error: [$injector:unpr] Unknown provider: $scope, $locationProvider <- $scope, $location.

var app = angular.module('myApp.controllers', []);

app.controller('Signup', ['$scope, $location', function($scope, $location) {
    $scope.checkEmailValid = function(){
        //TODO make a decision about whether to go somewhere, if true do this:
        $location.path('/view2');
    };
}]);

Am I missing something about how to inject the location service? I haven't configured $locationProvider, but doing so doesn't seem to help.

Était-ce utile?

La solution

You forgot the quotes around $scope and $location :

var app = angular.module('myApp.controllers', []);

app.controller('Signup', ['$scope', '$location', function($scope, $location) {
    $scope.checkEmailValid = function(){
        //TODO make a decision about whether to go somewhere, if true do this:
        $location.path('/view2');
    };
}]);

This should to the trick !

Autres conseils

Try simpler form (without array form - probably missing quote is your problem):

app.controller('Signup', function($scope, $location) {
    $scope.checkEmailValid = function(){
        //TODO make a decision about whether to go somewhere, if true do this:
        $location.path('/view2');
    };
});

Minification can be solved in build time using ngMin and this form is less error prone and more readable

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top