rafg
rafg

Reputation: 165

Directives with static value

If I use an AngularJS directive with a static value, let's say:

<input type="text" ng-readonly="true" />

My question around this:

Will this directive be re-evaluated on AngularJS cycles leading to a drop on performance? (think on a heavier scenario)

Upvotes: 2

Views: 77

Answers (1)

Davin Tryon
Davin Tryon

Reputation: 67296

Will this directive be re-evaluated on AngularJS cycles:

Yes, the value of ng-readonly is an Angular Expression and this expression could be a more complex ternary or function reference. So, the directive must do dirty checking on it (for the more complex cases).

leading to a drop on performance

This depends on many things and should be tested and benchmarked before making assumptions. A lot of dirty-checking can happen without any noticeable performance drop.

Since Angular 1.3, you can use the bind-once syntax (::) to possibly not add the value to the watch queue, but I'm not sure about how this would work with true:

<input type="text" ng-readonly="::true" />

Upvotes: 1

Related Questions