在NG-点击angular.js价值解析 [英] angular.js parsing value in ng-click
本文介绍了在NG-点击angular.js价值解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的行为在孩子控制器列表:
I have a list of actions in a child controller:
$scope.actions = [{action:"onClick()",name:"Test"}];
在一个浏览模板,我有看起来像这样的一个按钮,下拉组:
On a browse template i have a button dropdown group that looks like this:
<li ng-repeat="action in actions">
<a href="" ng-click="action.action">{{action.name}}</a>
</li>
这是我遇到的问题是,NG-点击应调用,在这个例子中,的onClick()
的功能,但如果我把 NG-点击={{action.action}}
它打破了。
The problem that I'm having is that ng-click should call, in this example the onClick()
function, but if i put ng-click="{{action.action}}"
it breaks.
这甚至可能吗?
推荐答案
编辑:我不好,你没有一个错字
my bad, you don't have a typo.
您不需要 {{}}
,如果它是元素的属性。但我真的不知道你希望当您尝试调用一个字符串,发生什么事,它需要的功能。
You don't need {{}}
if it's an attribute of the element. But I'm really not sure what you expect to happen when you try to call a string, it needs to be a function.
尝试是这样的:
var someFunc = function() {
console.log("someFunc")
};
$scope.actions = [{action:someFunc,name:"Test"}];
<li ng-repeat="action in actions">
<a href="" ng-click="action.action()">{{action.name}}</a>
</li>
演示。
这篇关于在NG-点击angular.js价值解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文