From 6aa3cfc31b14bfe74d89030fb6c2d615e44f2845 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Wed, 7 Mar 2012 14:04:14 -0800 Subject: docs($compileProvider.directive): Update iAttrs docs --- ...ular.module.ng.$compileProvider.directive.ngdoc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'docs/content/api/angular.module.ng.$compileProvider.directive.ngdoc') diff --git a/docs/content/api/angular.module.ng.$compileProvider.directive.ngdoc b/docs/content/api/angular.module.ng.$compileProvider.directive.ngdoc index 56dbcbd8..40f272c0 100644 --- a/docs/content/api/angular.module.ng.$compileProvider.directive.ngdoc +++ b/docs/content/api/angular.module.ng.$compileProvider.directive.ngdoc @@ -500,7 +500,7 @@ Executed after the child elements are linked. Safe to do DOM transformation in h The attributes object - passed as a parameter in the link() or compile() functions - is a way of accessing: - * *normalize attribute names:* Since a directive such as 'ngBind' can be expressed in many ways + * *normalized attribute names:* Since a directive such as 'ngBind' can be expressed in many ways sucha s as 'ng:bind', or 'x-ng-bind', the attributes object allows for a normalize accessed to the attributes. @@ -511,6 +511,26 @@ accessing: * *supports interpolation:* Interpolation attributes are assigned to the attribute object allowing other directives to read the interpolated value. + * *observing interpolated attributes:* Use `$observe` to observe the value changes of attributes + that contain interpolation (e.g. `src="{{bar}}"`). Not only is this very efficient but it's also + the only way to easily get the actual value because during the linking phase the interpolation + hasn't been evaluated yet and so the value is at this time set to `undefined`. + +
+function linkingFn(scope, elm, attrs, ctrl) {
+  // get the attribute value
+  console.log(attrs.ngModel);
+
+  // change the attribute
+  attrs.$set('ngModel', 'new value');
+
+  // observe changes to interpolated attribute
+  attrs.$observe('ngModel', function(value) {
+    console.log('ngModel has changed value to ' + value);
+  });
+}
+
+ # Understanding Transclusion and Scopes -- cgit v1.2.3