If I use the ternary operator in my Angular.js view will it be executed on every digest(like functions) or only if the variables necessary for the decision are changed?
Example:
<div>{{ui.isTrue ? "foo" : "bar"}}</div>
or:
<div ng-bind="ui.isTrue ? 'foo' : 'bar'"></div>
Would it be executed on every digest or only when is ui.IsTrue changed?
In AngularJS, every expression including the ternary operator will be executed:
ui.isTrue
variable is changed in the angular app scope
.If you take a look at angular scope documentation and specifically Scope as Data-Model section, you will see that:
Scope is the glue between application controller and the view. During the template linking phase the directives set up
$watch
expressions on the scope.The
$watch
allows the directives to be notified of property changes, which allows the directive to render the updated value to the DOM.
So the view will be always notified when a property in the scope changes, so the ternary expression will be automatically evaluated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With