javascript - angular click event share to other click -
let's have 2 links using angularjs ng-click, both have same on click event pass same scope variable.
ui.myclick(myvar1, myvar2, myvar3) <a ng-click="ui.myclick(myvar1, myvar2, myvar3)">link1</a> <a ng-click="ui.myclick(myvar1, myvar2, myvar3)">link2</a>
is possible define on click handler somewhere in html reuse it? this:
ng-init="var commonclick = ui.myclick(myvar1, myvar2, myvar3)"
then ng-click just:
<a ng-click="commonclick">link1</a> <a ng-click="commonclick">link2</a>
you can add function in controller , use on ng-click attribute, this:
<div ng-controller="myctrl m"> <a ng-click="m.f(arg)">link 1</a> <a ng-click="m.f(arg)">link 2</a> </div> <script> angular .module('app', []) .controller('myctrl', ['$scope', function($scope) { $scope.f = function(arg) { console.log(arg); } }]) ; </script>
Comments
Post a Comment