Failed to enter $ 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 introduce a location service? I have not configured $ locationProvider, but doing this does not seem to help.

+4
source share
2 answers

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');
    };
}]);

It must be a trick!

+5
source

Try to simplify the form (without an array form - perhaps a 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');
    };
});

Minimization can be resolved during build using ngMin, and this form is less error prone and more readable

+1
source

Source: https://habr.com/ru/post/1540438/


All Articles