$ location.path of Angular has changed?

1

Good morning everyone!

I'm trying to do a function with $ location.path ('/ main'); and when the function ischamo, the following message appears in the console:

  

TypeError: Can not read property 'path' of undefined

Why this?

.controller('loginCtrl', ['$scope', '$stateParams', function ($scope, $stateParams, $http, $location) {

    $scope.fazerLogin = function(usuario){
        /*$http.post("", usuario).success(function(data){

        });*/
    $location.path('/main');
}


}])
    
asked by anonymous 17.02.2017 / 12:24

1 answer

1

Your first line with the controller statement is incomplete. The correct would be:

...
.controller('loginCtrl', ['$scope', '$stateParams', '$http', '$location', function ($scope, $stateParams, $http, $location) {
...

Now an improvement point. If you use Angular Styleguide (which is a very interesting material that greatly increases the written code), you should declare controller as follows:

...
.controller('LoginCtrl', LoginCtrl);

LoginCtrl.$inject = ['$scope', '$stateParams', '$http', '$location'];

function LoginCtrl($scope, $stateParams, $http, $location) {
...
    
17.02.2017 / 12:26