Gab*_*pes 5 state params angularjs angular-ui-router
我从这两种方法中得到意想不到的结果.
我让我的美元状态变得混乱
$stateProvider
.state('status', {
url: "/status/:payment",
controller: 'QuestCtrl',
templateUrl: "index.html"
});
Run Code Online (Sandbox Code Playgroud)
在控制器上我有:
angular.module('quest').controller('QuestCtrl',function($scope,$stateParams,$state){
console.log($stateParams.payment); // undefined
console.log($state); // Object {params: Object, current: Object, $current: extend, transition: null}
}
Run Code Online (Sandbox Code Playgroud)
我已经在其他项目中使用了$ stateParams并且它工作但现在我无法弄清楚这里发生了什么..
['$scope','$stateParams','$state',
function($scope, $http, $stateParams, $state)
Run Code Online (Sandbox Code Playgroud)
服务名称与变量不匹配。
所以$http实际上是$stateParams服务,$stateParams实际上是$state服务,$state是未定义的。
我的建议:停止使用这种数组表示法,它会使代码变得混乱,并且是错误的常见来源。相反,使用 ng-annotate 作为构建过程的一部分,它将为您正确地完成它。
| 归档时间: |
|
| 查看次数: |
12534 次 |
| 最近记录: |