Perhaps a JSFiddle would help us understand each other better. We had a 
short conversation with LLoyd about this, so I will try to illustrate the 
context and what is that we don’t understand. Here is the 
JSFiddle: http://jsfiddle.net/gurdiga/9KeKM/.

As you will see in your browser console, when you click “Increase magic!” 
button it increases magicLevel in the parent scope, and also changes the 
myMagic directive’s incantation attribute that interpolates it. Then, in 
the link function the incantation attribute is watched for changes with 
both $scope.$watch and attrs.$observe, which *both are triggered*, and this 
is the very phenomenon that LLoyd and I were wondering about: which 
observation method is appropriate to use?


On Friday, February 7, 2014 5:49:42 AM UTC+2, Mike Alsup wrote:
>
> You need to use $observe to watch DOM attributes who's values contain 
> interpolation. 
>
> <span title="Hello {{name}}">blah</span>
>
> attrs.$observe('title', function() {
>    ...
> });
>
> $watch can not be used for string expressions that contain interpolation.
>
> http://ng.malsup.com/#!/$watch-vs-$observe
>
>
>
>
> On Fri, Jan 31, 2014 at 9:16 AM, LLoydsensei <[email protected]<javascript:>
> > wrote:
>
>> Hi guys.
>>
>> API documentation (
>> http://docs.angularjs.org/api/ng.$compile#description_comprehensive-directive-api_attributes)
>>  
>> says  "[...] during the linking phase the interpolation hasn't been 
>> evaluated yet and so the value is at this time set to undefined."
>>
>> 1) I cannot understand why someone would use attrs.$observe() instead of 
>> $scope.$watch(), since both appear to work the same way
>> 2) I don't understand why the documentation talks about the interpolation 
>> being undefined during the linking phase when this 
>> http://jsfiddle.net/3Vh43/1/ proves the contrary
>>
>> Did I happen to stumble upon a particular case in my jsfiddle where it 
>> works or is the documentation wrong there?
>>
>> Regards,
>> LLoyd
>>
>> PS: Wiki says the same (
>> https://github.com/angular/angular.js/wiki/Understanding-Scopes#-directives
>> )
>> PPS: Tested on angular 1.1.5 and 1.2.10
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "AngularJS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/angular.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to