从$ HTTP获得的数据不能从NG-点击来获得服务 [英] data obtained from $http service cant be obtained from ng-click
本文介绍了从$ HTTP获得的数据不能从NG-点击来获得服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的控制器
的一部分:
function($scope, $http, $stateParams, $timeout, $q, $ionicPopup, $ionicActionSheet){
$http.get('topics/' + $stateParams.subTopicId + '.json').
success(function(data, status,header, config) {
$scope.questions = data;
});
}
现在这里是我的视图
的一部分:
Now here is a part of my view
:
<button ng-click="someFunc('{{questions[qNum].opt1}}')">
{{questions[0].opt1}}
</button>
In the above view {{questions[0].opt1}} works perfectly. But when passed as an arg to ng-click it becomes empty.
和再次出现在我控制器
:
function someFunc(aValue){
alert(aValue); // Empty
}
为什么变量的值安勤
空。
在另一方面,如果,我直接申报 $ scope.questions
里面我的控制器是这样的:
On the other hand if, I directly declare $scope.questions
inside my controller like this:
$scope.question = [
{ ... }
];
然后 someFunc
正确显示变量的值。这里发生了什么?
我在做什么错了?
Then someFunc
displays the value of the variable correctly. What is going on here?
What am I doing wrong?
推荐答案
试试这个:
<button ng-click="someFunc(questions[qNum].opt1)">
此外,显示属性,当你明确地绑定到元素0,但使用的是可变qNum,所以一定被定义在你的NG-点击。
Also, you are explicitly binding to element 0 when showing the property, but in your ng-click you are using a variable qNum, so be sure that is defined.
这篇关于从$ HTTP获得的数据不能从NG-点击来获得服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文