문제

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.

도움이 되었습니까?

해결책

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 !

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top