@@ -500,7 +500,7 @@ Executed after the child elements are linked. Safe to do DOM transformation in h
500
500
The attributes object - passed as a parameter in the link() or compile() functions - is a way of
501
501
accessing:
502
502
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
504
504
sucha s as 'ng:bind', or 'x-ng-bind', the attributes object allows for a normalize accessed to
505
505
the attributes.
506
506
@@ -511,6 +511,26 @@ accessing:
511
511
* *supports interpolation:* Interpolation attributes are assigned to the attribute object
512
512
allowing other directives to read the interpolated value.
513
513
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
+
514
534
515
535
# Understanding Transclusion and Scopes
516
536
0 commit comments