Understanding ng-click Arguments

Asked 2 years ago, Updated 2 years ago, 91 views

Is it possible to set more than one ng-click argument?

ng-click="click (argument 1, argument 2)"

In this way, I would like to give two arguments to click.
I look forward to your kind cooperation.

monaca angularjs

2022-09-30 18:20

1 Answers

Yes, it's possible.
You can create a click(arg1,arg2) method in $scope and specify it as ng-click.Try the snippet below.

 angular.module('app', [])
.run(function($rootScope){
  $rootScope.click=function(arg1,arg2){
    alert(arg1+arg2);
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>

<div ng-app="app">
<button ng-click="click(1,2)">Click</button>
</div>


2022-09-30 18:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.