search

Home  >  Q&A  >  body text

angular.js - How to know which button is called in the controller in angular?

This is how it is currently written

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

I want to know how to write directly in the controller instead of passing parameters in HTML?

过去多啦不再A梦过去多啦不再A梦2821 days ago574

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