Hmm, I wonder what would happen if I did that- Angular already actually
redefines A. Would my change override theirs? Hard to say.

Anyway I just ended up creating  a directive that wrapped a <div
ng-bind-html> in the template, put a watch on the bound-html value, and
used element.find('a').attr('target', '_blank'). Seems to work. Maybe this
is one of those times when using jqLite isn't against the rules.

e

On Fri Nov 21 2014 at 10:15:34 AM Kyle Cordes <[email protected]>
wrote:

> On Fri, Nov 21, 2014 at 11:05 AM, Eric Eslinger <[email protected]>
> wrote:
>
> I have some trusted HTML code coming off of my database. Due to the
>> vagaries of how it's created (text editor), none of the A elements have a
>> target="_blank" on them.
>>
>> It occurred to me this morning that instead of editing the way the HTML
>> is emitted from the editor, I could maybe alter how ng-bind-html and
>> $compile work to programmatically make sure that all the A elements inside
>> this particular custom directive have a target="_blank" on them. I don't
>> want to do that page-wide, since regular navigation in the app wants to
>> work as normal, but I want all user-generated links to open in a new tab.
>>
>> Anybody have any thoughts on how to approach this? I could brute-force it
>> with some transcludes and manually crawling the DOM, but it would be more
>> elegant if there was some interceptor I could register with the $compile or
>> $sanitize service. It doesn't look like this is the case, though.
>>
>>
> The following is either an horrible hack, or an elegant use of AngularJS
> capabilities.  It is OK to put directives on things built in to HTML,
> AngularJS does it extensive. So...
>
> Make a directive on element "a". Have it look up the DOM, and it finds it
> is inside something with ng-bind-html, add target=_blank to itself.
>
>
> --
> Kyle Cordes
> http://kylecordes.com
>
>  --
> 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.
>

-- 
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