search

Home  >  Q&A  >  body text

angular.js - angular里如何在控制器里知道被调用的按钮是第几个?

目前是这样写的

<li ng-repeat="data in datas"><a ng-click="handle($index)"></a></li>

我想知道如何在控制器里直接写而不是html传参数过去?

过去多啦不再A梦过去多啦不再A梦2743 days ago524

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-15 16:51:50

    <button ng-click="onClick($event)">Button</button>
    

    $scope.onClick = function(evt) {
      var index = $(evt.target).index();    //jquery
    }
    

    reply
    0
  • 高洛峰

    高洛峰2017-05-15 16:51:50

    Although I don’t understand what the questioner wants to ask, I usually write like this in this situation:

    <li ng-repeat="data in datas"><a ng-click="handle(data,$index)"></a></li>
    

    reply
    0
  • Cancelreply