简体   繁体   中英

In angularjs why does ng-click on an element also fire other method calls in the element's attributes?

I'm learning angularJS, and am trying to understand why multiple methods are invoked when only one is actually called. Within this line:

<li  ng-repeat="i in names" style="position: relative; top:{{mar(i)}}px; z-index:{{i}}; background-color: orange;" ng-click="clicker(i, $index)">{{i + " " + $index}}</li>

So I have two "calls" in this line:

  1. Within the style attribute - this calculates the top offset.
  2. ng-click= my function to do stuff when the element is clicked.

When I click the element - the mar(i) is called ALONG WITH the ng-click function.

I am just trying to understand why this occurs. I have a plunk here that you can try out.

这是因为您要绑定到要说{{mar(i)}} 。这意味着,每当有一个$ digest时,例如在触发ng-click之后,该方法就必须进行评估,以便可以更新视图。

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