AngularJS-TypeError:对象#<Scope>没有方法'path'

归零

我尝试在按页面上的按钮时进行简单的重定向,但是由于某种原因,我一直收到以下错误。

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

不知道是什么原因导致了这种情况的发生。我的代码如下:

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()")

我究竟做错了什么?

萨帕尔

您将$rootScope作为变量注入$location反之亦然。只需正确纠正注射即可。

使用

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

代替

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章