ReturnToZero
ReturnToZero

Reputation: 375

Angularjs - TypeError: Object #<Scope> has no method 'path'

I am trying to make a simple redirect when pressing a button on the my page, but for some reason I keep getting the following error.

TypeError: Object #<Scope> has no method 'path'

Not sure what causes it to happen. My code is as following:

controller.js

mycontroller.controller('OrderCtrl', ['$scope', '$http', '$rootScope','$location',function($scope, $http, $location, $rootScope) {
...
$scope.confirmOrder = function confirmOrder() {
    $location.path("/order");
}; 
...
}]);

page.jade

input.green-button(type="submit",value="Confirm order",ng-controller="OrderCtrl", ng-click="confirmOrder()")

What am I doing wrong?

Upvotes: 0

Views: 294

Answers (1)

Satpal
Satpal

Reputation: 133423

You are injecting $rootScope as variable $location and vica-versa. Just correct the injection correctly.

Use

mycontroller.controller('OrderCtrl', 
                        ['$scope', 
                         '$http', 
                         '$rootScope', 
                         '$location', function($scope, 
                                               $http, 
                                               $rootScope, 
                                               $location) {
}]); 

instead of

mycontroller.controller('OrderCtrl', 
                        ['$scope', 
                         '$http', 
                         '$rootScope', //Notice here
                         '$location', function($scope, 
                                               $http, 
                                               $location, //Notice here
                                               $rootScope) {
}]);

Upvotes: 3

Related Questions