Dealing with DOM Manipulations in AngularJS

前端 未结 2 451
野趣味
野趣味 2020-12-02 11:14

When I perform DOM manipulation (add new HTML) using jQuery, AngularJS doesn\'t automatically detect variables in the new HTML and replace them with their values. For exampl

2条回答
  •  盖世英雄少女心
    2020-12-02 11:44

    You have to inject $compile (http://docs.angularjs.org/api/ng.$compile) and use it so angular knows about the new html.

    $compile('

    {{row}}

    However, it is frowned upon in angular to do DOM manipulation in your controllers. You want your controllers to handle business and your views to handle the view.

    Try a directive to do what you want. http://docs.angularjs.org/guide/directive

提交回复
热议问题