简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM