Skip to content

Commit 6aa3cfc

Browse files
committed
docs($compileProvider.directive): Update iAttrs docs
1 parent 6491206 commit 6aa3cfc

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/content/api/angular.module.ng.$compileProvider.directive.ngdoc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ Executed after the child elements are linked. Safe to do DOM transformation in h
500500
The attributes object - passed as a parameter in the link() or compile() functions - is a way of
501501
accessing:
502502

503-
* *normalize attribute names:* Since a directive such as 'ngBind' can be expressed in many ways
503+
* *normalized attribute names:* Since a directive such as 'ngBind' can be expressed in many ways
504504
sucha s as 'ng:bind', or 'x-ng-bind', the attributes object allows for a normalize accessed to
505505
the attributes.
506506

@@ -511,6 +511,26 @@ accessing:
511511
* *supports interpolation:* Interpolation attributes are assigned to the attribute object
512512
allowing other directives to read the interpolated value.
513513

514+
* *observing interpolated attributes:* Use `$observe` to observe the value changes of attributes
515+
that contain interpolation (e.g. `src="{{bar}}"`). Not only is this very efficient but it's also
516+
the only way to easily get the actual value because during the linking phase the interpolation
517+
hasn't been evaluated yet and so the value is at this time set to `undefined`.
518+
519+
<pre>
520+
function linkingFn(scope, elm, attrs, ctrl) {
521+
// get the attribute value
522+
console.log(attrs.ngModel);
523+
524+
// change the attribute
525+
attrs.$set('ngModel', 'new value');
526+
527+
// observe changes to interpolated attribute
528+
attrs.$observe('ngModel', function(value) {
529+
console.log('ngModel has changed value to ' + value);
530+
});
531+
}
532+
</pre>
533+
514534

515535
# Understanding Transclusion and Scopes
516536

0 commit comments

Comments
 (0)