On Fri, Nov 21, 2014 at 11:05 AM, Eric Eslinger <eric.eslin...@gmail.com> 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 angular+unsubscr...@googlegroups.com. To post to this group, send email to angular@googlegroups.com. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.