$状态,$ stateParams,越来越未定义的对象 [英] $state, $stateParams, getting undefined object
本文介绍了$状态,$ stateParams,越来越未定义的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从两个方法意想不到的效果。
I am getting unexpected results from both methods.
我有我的$状态的ConfigEd
I have my $state configed
$stateProvider
.state('status', {
url: "/status/:payment",
controller: 'QuestCtrl',
templateUrl: "index.html"
});
和控制器上的我有:
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}
}
我已经用$ stateParams在其他项目和它的工作,但现在我无法弄清楚是怎么回事..
I already used $stateParams in other projects and it worked but now I can't figure out what is going on here..
推荐答案
正如我已经评论上面你忘了注入$ http服务
As I already commented above You forgot to inject $http service
angular.module('quest').controller('QuestCtrl',
['$scope','$http','$stateParams','$state',function($scope,$http,$stateParams,$state){
console.log($stateParams); // Empty Object
console.log($stateParams.payment); // Empty Object
console.log($state); // I get the entire state, I can see that my params are there.
console.log($state.params);
}
所以你的参数不匹配,它原来你会得到$ stateparms $状态和$状态是空的。
和$ HTTP保持$状态:P
So your parameters mismatch and it turns out you will get $state in $stateparms and $state is empty. And $http hold $state :P
希望它能帮助:)
这篇关于$状态,$ stateParams,越来越未定义的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文