Angularjs - 重复和点击 [英] Angularjs - repeat and click
本文介绍了Angularjs - 重复和点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使angularjs项目。我有以下的code:
HTML
< UL>
<李NG重复=答案question.answers>
<按钮式=按钮NG点击=答案($指数)> {{回答}}({{$指数}})LT; /按钮>
< /李>
< / UL>
控制器:
.controller('QuestionCtrl',['$范围','问题',函数($范围,问题解答){
$ scope.question = Questions.query(); $ scope.answer =功能(ANS){
的console.log(点击+ ANS);
}
}]);
生成的列表如预期,但是当我点击的元素,我得到这个错误信息:
错误:fnPtr不是一个函数Parser.prototype.functionCall /&LT; @http://本地主机:8000 / APP2 / lib目录/角/ angular.js:10169 ngEventDirectives[directiveName]</<.compile/</</<@http://localhost:8000/app2/lib/angular/angular.js:17823 Scope.prototype.$eval@http://本地主机:8000 / APP2 / lib目录/角/ angular.js:11906 Scope.prototype.$apply@http://本地主机:8000 / APP2 / lib目录/角/ angular.js :12006 ngEventDirectives[directiveName]</<.compile/</<@http://localhost:8000/app2/lib/angular/angular.js:17822 createEventHandler /事件处理程序/&LT; @http://本地主机:8000 / APP2 / lib目录/角/ angular.js:2610的forEach @ HTTP://本地主机:8000 / APP2 / lib目录/角/ angular.js:309 createEventHandler /事件处理程序@http://本地主机:8000 / APP2 / lib目录/角/ angular.js:2609
解决方案
您应该对功能使用一些其他的名称 $ scope.answer
$ scope.answer1 =功能(ANS){
的console.log(点击+ ANS);
}
HTML
&LT; UL&GT;
&LT;李NG重复=答案question.answers&GT;
&LT;按钮式=按钮NG点击=ANSWER1($指数)&GT; {{回答}}({{$指数}})LT; /按钮&GT;
&LT; /李&GT;
&LT; / UL&GT;
I try to make an angularjs project. I have the following code:
HTML:
<ul>
<li ng-repeat="answer in question.answers">
<button type="button" ng-click="answer($index)">{{answer}} ({{$index}})</button>
</li>
</ul>
Controller:
.controller('QuestionCtrl', ['$scope', 'Questions', function($scope, Questions) {
$scope.question = Questions.query();
$scope.answer = function(ans) {
console.log('clicked' + ans);
}
}]);
The list is generated as expected, but when I click on on of the elements, I get this error message:
Error: fnPtr is not a function Parser.prototype.functionCall/<@http://localhost:8000/app2/lib/angular/angular.js:10169 ngEventDirectives[directiveName]</<.compile/</</<@http://localhost:8000/app2/lib/angular/angular.js:17823 Scope.prototype.$eval@http://localhost:8000/app2/lib/angular/angular.js:11906 Scope.prototype.$apply@http://localhost:8000/app2/lib/angular/angular.js:12006 ngEventDirectives[directiveName]</<.compile/</<@http://localhost:8000/app2/lib/angular/angular.js:17822 createEventHandler/eventHandler/<@http://localhost:8000/app2/lib/angular/angular.js:2610 forEach@http://localhost:8000/app2/lib/angular/angular.js:309 createEventHandler/eventHandler@http://localhost:8000/app2/lib/angular/angular.js:2609
解决方案
You should use some other name for function $scope.answer
$scope.answer1 = function(ans) {
console.log('clicked' + ans);
}
HTML:
<ul>
<li ng-repeat="answer in question.answers">
<button type="button" ng-click="answer1($index)">{{answer}} ({{$index}})</button>
</li>
</ul>
这篇关于Angularjs - 重复和点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文