Complementing the answers trying to explain Why and Like we should use the expression.
Methods of use
In addition to the classic use with {{::meuModelo}}
can also be used through the directive ngBind
: <span ng-bind="::meuValor"></span>
Why use?
Every time we make the declaration of {{meuValor}}
in view, a new watcher
is generated. Throughout the digest()
Angularjs will compare the old Watcher value to the new value and update it if different. When we use ::
we’re telling the AngularJS
not to re-evaluate that watcher
and this will increase the speed of the application, since there will be a smaller number watchers
to be analyzed.
Examples of use
We should use Oneway Databind or ::
where we are certain that a given data will not change within the application, if there is any possibility that the data may be changed, its standard use shall be maintained.
The most common use is with the directive ngRepeat
, which is the one that generates the most watchers
and there is also a different mode of use, since we can apply not only to the value of an array object, but to an entire array. See:
$scope.listaEndereco = [
{id: 1, cidade: 'São Paulo', Estado: 'SP'},
{id: 2, cidade: 'Rio de Janeiro', Estado: 'RJ'},
{id: 3, cidade: 'Curitiba', Estado: 'PR'},
...
]
<ul>
<li ng-repeat="endereco in $scope.listaEndereco track by endereco.id">{{endereco.cidade}}</li>
</ul>
In this example, if you are sure that address data, such as city name, cannot be changed, you can use: {{::endereco.cidade}}
In the same example, if you are also sure that the entire address list will not be changed, you can combine and have a code like this:
<li ng-repeat="endereco in ::$scope.listaEndereco track by ::endereco.id">{{::endereco.cidade}}</li>
In this way the whole scope will be disregarded of the cycle and not only the value of the city name only.
This is very useful when working with large lists and with the use of ngRepeat
, which is the most impactful in the generation of watchers
.
Example - https://plnkr.co/edit/? p=preview
– Diego Souza