Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

javascript - 一键单击如何添加许多功能?(How to add many functions in ONE ng-click?)

I've be looking for how to execute this but I can't find anything related so far, :( I could nest both functions yes but I'm just wondering if this is possible? I'd like to do this literally:(我一直在寻找如何执行此操作,但到目前为止我还没有找到任何相关的东西,:(我可以嵌套两个函数,但是我只是想知道这是否可能吗?)

<td><button class="btn" ng-click="edit($index) open()">Open me!</button></td> My JS code at the moment:(目前我的JS代码:) $scope.open = function () { $scope.shouldBeOpen = true; }; $scope.edit = function(index){ var content_1, content_2; content_1 = $scope.people[index].name; content_2 = $scope.people[index].age; console.log(content_1); }; I'd like to call two functions with just one click, how can I do this in angularJS?(我想一键调用两个函数,如何在angularJS中做到这一点?) I thought it'd be straight forward like in CSS when you add multiple classes...but it's not :((我认为当您添加多个类时,它将像在CSS中一样简单...但是不是:()   ask by YoniGeek translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have 2 options :(您有2个选择:)

Create a third method that wrap both methods.(创建包装这两种方法的第三个方法。) Advantage here is that you put less logic in your template.(这样做的好处是可以减少模板中的逻辑。) Otherwise if you want to add 2 calls in ng-click you can add ';'(否则,如果要在ng-click中添加2个呼叫,则可以添加';'。) after edit($index) like this(像这样edit($index)之后) ng-click="edit($index); open()" See here : http://jsfiddle.net/laguiz/ehTy6/(看到这里: http : //jsfiddle.net/laguiz/ehTy6/)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...