What is "= *" in AngularJS

I came across this way isolate binding:

scope: {
   property: "=*"
}

What does an asterisk mean here? Can someone provide an example?

+4
source share
3 answers

The binding of the isolate to =*lies in shallow observations of the change in the collection.

Let me clarify a bit:

Typically, watchCollection variables are used in scripts, as shown below:

$scope.arr = ['foo', 'bar', 'lorem', 'ipsum'];
$scope.arrCount = 4;

$scope.$watchCollection('arr', function(new, old) {
  $scope.arrCount = new.length;
}); 

But what if you want to bind an object to an html attribute?

<my-directive my-attr="arr"><!--$scope.arr-->

And if you do this:

scope: {
   myAttr: "=*"
}

Now the attributes of the directive are assigned, since it should be a small clock. And using watchCollection is good to use this time.

, =* , (, $watchCollection $watch), = * or = attr (=? or = *? attr, ), docs.

= watchCollection, , =* . , =* , , $watchCollection , $watch , :

if (definition.collection) { //using `=*`
  removeWatch = scope.$watchCollection(attrs[attrName], parentValueWatch);
} else { //using `=`
  removeWatch = scope.$watch($parse(attrs[attrName],
     parentValueWatch), null, parentGet.literal);
}

, collection, =*.

+6

.

angular docs:

$ , . , , ( angular.equals). $watchCollection: use = * or = attr (=? Or = *? Attr, ).

+2

Doc:

= = attr - scope , attr.

$watch , .

= * $watchCollection.

$watch vs $watchCollection.

.

0

All Articles