Hi Justin

That works in this specific case, but I want the directive to be generally 
applicable to any interpolated child content.

The use case I'm looking at is a applying a 3rd party syntax highlighter to 
a <code> element that contains dynamically generated code. The highlighter 
needs to work with the finished, compiled and interpolated DOM, and needs 
to re-run whenever something in the DOM changes. I want to be able to 
re-use the directive for different <code> blocks, and let other developers 
use it in future. I can't really do that if I need to hard code every watch 
expression into the linking function.

On Wednesday, October 15, 2014 11:49:52 AM UTC+1, Justin Walsh wrote:
>
> Hi Jon
>
> The linking phase of the directive is the place where you *could *set up 
> watchers.  For example:
>
> app.directive('myDirective', function() {
>   return {
>     restrict: 'A',
>     link : function(scope) {
>       scope.$watch('some.expression', function(newValue, oldValue) {
>
>       });
>     }
>   }
> })
>
>
> Working example <http://plnkr.co/edit/ODXNps?p=preview>: 
> http://plnkr.co/edit/ODXNps?p=preview
>
> Regards
> Justin
>
> On Wednesday, October 15, 2014 12:19:42 PM UTC+2, Jon Rimmer wrote:
>>
>> If I have an element with a custom directive applied, containing an 
>> expression:
>>
>> <div my-directive>
>>   {{ some.expression }}
>> </div>
>>
>> How can my-directive know when some.expression has been evaluated and 
>> replaced in the DOM? How can it be notified when the expression changes and 
>> the DOM is updated?
>>
>> I thought the post-link stage in the life-cycle was intended for this, 
>> but even at that point, accessing the element's HTML content reveals the 
>> expression has not been evaluated.
>>
>> It seems like this is a vital part of the life-cycle to be able to hook 
>> into, but I can't see any obvious way to do it?
>>
>> Jon
>>
>

-- 
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/d/optout.

Reply via email to