Powered by Blogger.

Wednesday 4 March 2015

Angualr Question

By Unknown  |  02:22 No comments

why ng-bind is better than {{}} in angular?
  • The {{}} is much slower.
  • you might see the actual Hello, {{user.name}} for a second before user.name is resolved (before the data is loaded)
  • in case of {{}}whole text "Hello, {{user.name}}" enclosed by < div > will be copied and stored in memory . but ng-bind will only stored the value of variable in memory , angular will register a watcher where the watch expression consists of the variable only.
  • The brackets on the other hand will be dirty checked and refreshed in every $digest, even if it's not necessary.
  • This ng-bind is a directive and will place a watcher on the passed variable. So the ng-bind will only apply, when the passed value does actually change.
Example:-
<div>  Hello, {{user.name}}</span></div>
<div>  Hello, <span ng-bind="user.name"></span></div>

if you write like below then , you will find person is undefined(in older version of Angular).
<li ng-repeat="person in people">
  Hello, {{calculateTotalPoints(person)}}
</li>

 You have to write:
<li ng-repeat="person in people">
  Hello, <span ng-bind="calculateTotalPoints(person)"></span>
</li>

In the controller, you can define the function:
$scope.calcualteTotalPoints = function(person){
     ....
};


Author: Unknown

Hello, I am Author, decode to know more: In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet.

0 comments:

Recent Articles

© 2014 Learning Java. WP themonic converted by Bloggertheme9. Published By Gooyaabi Templates
TOP