using directives within ng-bind-html (unsafe)

5,332 views
Skip to first unread message

Jim Lyndon

unread,
Feb 19, 2013, 6:11:55 PM2/19/13
to ang...@googlegroups.com
Is there a way to use directives within ng-bind-html-unsafe?  I'm executing a transclusion using a template that includes a ng-bind-html-unsafe directive, and the html for the ng-bind-html-unsafe is added within the linking phase, so any directives within this html aren't compiled.


Thanks 

Jim

Joshua Miller

unread,
Feb 19, 2013, 7:33:22 PM2/19/13
to angular
Hello!

You just have to $compile it first: http://docs.angularjs.org/api/ng.$compile. You can also $sanitize it if you need to. Something like this should work I think:

scope.content = $compile( theStringToCompile )( scope );

and then in your template:

<div ng-bind-html-unsafe="content"></div>

Josh



Jim

--
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+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jim Lyndon

unread,
Feb 19, 2013, 8:08:48 PM2/19/13
to ang...@googlegroups.com
Thanks Josh, that got me to where I needed to be.  Yeah i was looking to do some manipulation during the compile.  What I was looking for turned to be something like this:

var compiledString = angular.element(theStringToCompile);
$compile(
compiledString )(scope, function(clonedElement, scope) {
// do work and dom manipulation
}



Jim

Manuel de la vega

unread,
Jun 2, 2013, 8:35:51 AM6/2/13
to ang...@googlegroups.com
Hi!

I found this thread for the same question, but if I try to insert a directive within another, it doesn't work. Here is fiddle with the problem. Its like to show a toString() from the compiled element. Could anybody help me, please?

thanks,

Manuel 
Reply all
Reply to author
Forward
0 new messages