how to pass angular js variable inside onclick function as parameter

前端 未结 9 1629
一生所求
一生所求 2020-12-15 20:37

I have tried to pass AngularJS variable as argument value inside onclick() to call javascript function. Can anyone guide me on how to do it?

My code:

相关标签:
9条回答
  • 2020-12-15 21:08

    I had a case where I could not use ng-click due to window binding. Did not get direct answer but the below did work for me. I know it is not a good solution but workable in my case.

    angular.element(this).scope().ctrlName.variable

    You can try using your own class structure. So the click will be as below:

    onclick="test(angular.element(this).scope().ctrlName.ObjName.variable)"

    0 讨论(0)
  • 2020-12-15 21:11

    If you still want to use onclick , this is work for me , I hope it work for you too.

    <div id="{{filterList.id}}" onclick="deleteArrival(this.id)" class="table-icon deleteIcon">{{filterList.id}}</div>
    
    0 讨论(0)
  • 2020-12-15 21:11

    You are not allowed to create a binding for event handler attributes like onclick, onload, onsubmit, etc. in angularjs because, there is no practical value in binding to these attributes and doing so it only exposes your application to security vulnerabilities like XSS. For these reasons binding to event handler attributes (all attributes that start with on and formaction attribute) is not supported in angularjs.

    For your case,

    Inside ng-repeat, use ng-click for sending values to your function and declare that function in controller.

    See here for documentation of ng-click

    Hope this helps !

    0 讨论(0)
提交回复
热议问题