简体   繁体   English

ng-click=function() 在 ng-reapeat 中是如何工作的? 它是否创建了作用域函数的多个引用?

[英]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.我有一个超过 2000 名员工的 ng-repeat 数据,这些数据显示在行和每个重复行/块内,我有一个函数将工资信息传递给指令进行一些处理。 I am binding function on ng-click="calcSalary(emp)".我在 ng-click="calcSalary(emp)" 上绑定函数。 Now my question is will ng-click="calcSalary(emp)" will be created 2000 times?现在我的问题是 ng-click="calcSalary(emp)" 会被创建 2000 次吗? And 2000 different reference will be stored at backend?后端会存储 2000 个不同的引用? Will 2000 calcSalary() functions will be created attached to scope?将创建 2000 个 calcSalary() 函数附加到作用域吗? 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?有什么办法我们只写 ng-click="calcSalary(emp)" 并根据单击的特定行传递员工数据?

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.即使您在 ng-repeat 中创建,它也会被创建 n 次,但会被实例化一次并在您仅单击时产生影响。

Read about it Angular ng-click event delegation阅读Angular ng-click event delegation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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