AngularJS and generated elements

后端 未结 3 481
失恋的感觉
失恋的感觉 2021-01-03 02:45

We have some third party javascript components that are generating some html elements. I\'d like to couple it with AngularJS.

I\'ve tried this code

         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-03 03:12

    This is the wrong way to do it, but for this particular scenario you'd want to do something like this: http://jsfiddle.net/wXZL7/1. Inject the $compile service.

    Again, this isn't the right way to do it with Angular. Angular's thing is 'You don't have to mess with the DOM in your controller, let the HTML and directives do that'.

    You want to create a directive to wrap whatever is generating your elements and let that do it. Read the directives guide for examples: http://docs.angularjs.org/guide/directive

提交回复
热议问题