KnewB KnewB - 10 days ago 7
AngularJS Question

Unable to inject $location service

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.

Answer

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 !