javascript - performance of angularjs ng-click inside ng-repeat -


This is a doubt of a verified problem, but .. .. I have worked with knockoutjs for some time And there was a display problem for binding many people - a better way to use a lot of jQuery to handle them .on ('click', ...)

Now when I do diving angularjs within my ng-repeat ng-repeat and inside of this second i have some button ng-click ..

  ; Ul & gt; & Lt; Li ng-repeat = "l in collection" & gt; & Lt; Button ng-click = "someFn ()" & gt; Click me & lt; / Button & gt; & Lt; Button ng-click = "someFn2 ()" & gt; Click me & lt; / Button & gt; & Lt; Button ng-click = "someFn3 (L)" & gt; Me & lt; / Button & gt; Click; & Lt; / Li & gt; & Lt; / Ul & gt;  

Does not it make too many event bindings? Or somehow can adapt angular?

It is hardly an adaptation in this case, what will happen if you have many nested ngreipets against whom optimization should be done? In fact, it is not easy to answer. In addition, repeat items can be controlled by another controller.

I see a small hackish approach to accomplishing the task.
We can call ngClick some method from the original method and allow the value to identify clicked items

   

The only question left to answer is how do we attain this identity value. We need our own instructions to apply for repetitive DOM elements, which adds this value to the element. After this we can get the value from the $ Event object.

  & lt; Ul ng-click = "itemClicked ($ event.target.itemIdentifier)" & gt; & Lt; Li ng-repeat = "l in collection" & gt; & Lt; Click the button - optimiztation = "el" & gt; Click me & lt; / Button & gt; & Lt; / Li & gt; & Lt; / Ul & gt;  

Of course, you have to check the undefined values.

This approach should be customized according to your needs, because you have many clickable elements within each repeated template. However, I hope this idea is clear.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -