Killer
Killer

Reputation: 219

One way binding in angularjs 1.4

According to Exploring Angular 1.3: One time bindings;

Using new syntax is as easy as starting an expression with ::. So if we apply the one-time expression to our example above, we change this:

<p>Hello {{name}}!</p>

To this

<p>Hello {{::name}}!</p>

and it is now one way binding.

But how can we create a one time binding when using angular directives such as ng-class? I tried the following, but it did not work:

ng-model="::name"
ng-class="['label',{'label-danger': 'High' == ::tsk.Priority}]:

Upvotes: 5

Views: 2873

Answers (1)

Killer
Killer

Reputation: 219

Got my answer here http://toddmotto.com/angular-one-time-binding-syntax/

{{ ::vm.user }}

<div ng-if="::vm.user.loggedIn"></div>

<div ng-class="::{ loggedIn: vm.user.loggedIn }"></div>

<ul>
  <li ng-repeat="user in ::vm.users"></li>
</ul>

Thanks to downvoters.

Upvotes: 12

Related Questions