如何添加多种功能于一身NG-点击? [英] How to add many functions in ONE ng-click?

查看:123
本文介绍了如何添加多种功能于一身NG-点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

香港专业教育学院在寻找如何执行这一点,但我无法找到到目前为止相关的任何东西,:(
我可以窝两个功能是的,但我只是想知道这是否可能?
我想从字面上做到这一点:

Ive be looking for how to execute this but I can't find anything related so far, :( I could nest both functions yes but Im 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>

我的JS code的时刻:

My JS code at the moment:

$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);
};

我想打电话只需点击一下两个函数,我怎么能在angularJS做到这一点?
我认为这会是直截了当像CSS当你添加多个类......但它不是:(

I'd like to call two functions with just one click, how can I do this in angularJS? I thought it'd be straight forward like in CSS when you add multiple classes...but it's not :(

感谢年时间

推荐答案

您有2个选项:


  1. 创建包两种方法的第三种方法。这里的优点是你把较少的逻辑在你的模板。

  1. Create a third method that wrap both methods. Advantage here is that you put less logic in your template.

否则,如果你想在加2调用纳克点击,您可以添加';'在编辑($指数)像这样

Otherwise if you want to add 2 calls in ng-click you can add ';' after edit($index) like this

NG-点击=编辑($指数); open()的

在这里看到: http://jsfiddle.net/laguiz/ehTy6/

这篇关于如何添加多种功能于一身NG-点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆