|ng-bind-html-unsafe, dynamic form, model issues||j.snyder||7/3/12 6:27 AM|
I am having a problem with adding in form elements dynamicly from a configuration obtained from a server. I am using ng-bind-html-unsafe, and the form renders perfectly, but I can't seem to figure out how to tie in an event handler so that when the element loads into the page, the form elements are compiled into the model.
jsFiddle example: http://jsfiddle.net/j_snyder/ctyfg/
Notice that property two and three don't update the model. I tried bootstrapping the parent div element, but I suspect a race condition, and don't know how to tie in an event handler to when the dom has been updated with the new html. Any help is appreciated.
|Re: [angular.js] ng-bind-html-unsafe, dynamic form, model issues||Oliver Batchelor||7/3/12 10:19 PM|
I gave it a go using a $compile directive, have a look here:
The second text "Property Two:" doesn't show up, not sure why that is
exactly - but it works at least.
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> For more options, visit this group at
|Re: [angular.js] ng-bind-html-unsafe, dynamic form, model issues||j.snyder||7/5/12 5:56 AM|
Nice work! Would be nice if the bind html unsafe did a compile on the section, since that is essentially what you are doing, but this looks like a great option. Thanks again.
Also, I noticed that if I started with an HTML tag and not Property Two, it rendered the whole block. Not sure why, but it works:
This seems like it could be a pretty useful solution for others too, is there a reason why there isn't a built in ability to do this?
|Re: [angular.js] ng-bind-html-unsafe, dynamic form, model issues||Oliver Batchelor||7/5/12 6:17 AM|
I guess normally you could generate the form from some data loaded as
JSON, probably more the 'angular way'.
Something like this:
Glad to help. Learning plenty myself.
|Re: [angular.js] ng-bind-html-unsafe, dynamic form, model issues||j.snyder||7/5/12 12:47 PM|
I dig that approach! That is so easy, not sure why I never thought of it. Probably because it is simple, and I was overthinking it per usual. I am going to switch over to that for sure.
Thanks again, +1 for all the help.
|Re: [angular.js] ng-bind-html-unsafe, dynamic form, model issues||Rick Richardson||7/5/12 1:13 PM|
This is so simple and elegant. It should go into a cookbook somewhere.