简体   繁体   中英

How does the ng-click=function() works inside ng-reapeat? Does it created multiple references of scope function?

I have a ng-repeat over 2000 employees data which is displayed in rows and inside each repeating row/block, I have a function which is passing salary information to directive for some processing. I am binding function on ng-click="calcSalary(emp)". Now my question is will ng-click="calcSalary(emp)" will be created 2000 times? And 2000 different reference will be stored at backend? Will 2000 calcSalary() functions will be created attached to scope? How will be the performance? Is there any way we write only ng-click="calcSalary(emp)" only ones and pass the employee data based on the particular row clicked?

No it does not have any performance issue! Even though you create inside ng-repeat it will be created n times but gets instanciated once and have impact when you click only.

Read about it Angular ng-click event delegation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM