When I dynamically add HTML using ng-bind-html how can I initiate a compile for this HTML

核能气质少年 提交于 2020-01-16 01:08:08

问题


My index.html contains the following element

...
<div class="col-md-6" ng-bind-html='module.docs.html'></div>
...

The module.docs.html property returns HTML like

<div ng-controller="accordion-demo-ctrl">
  <label class="checkbox">
    <input type="checkbox" ng-model="oneAtATime">
    Open only one at a time
  </label>

  <accordion close-others="oneAtATime">
    <accordion-group heading="Static Header, initially expanded" is-open="true">
      This content is straight in the template.
    </accordion-group>
    <accordion-group heading="{{group.title}}" ng-repeat="group in groups">
      {{group.content}}
    </accordion-group>
    <accordion-group heading="Dynamic Body Content">
      <p>The body of the accordion group grows to fit the contents</p>
        <button class="btn btn-default btn-sm" ng-click="addItem()">Add Item</button>
        <div ng-repeat="item in items">{{item}}</div>
    </accordion-group>
    <accordion-group is-open="isopen">
        <accordion-heading>
            I can have markup, too! <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': isopen, 'glyphicon-chevron-right': !isopen}"></i>
        </accordion-heading>
        This is just some content to illustrate fancy headings.
    </accordion-group>
  </accordion>
</div>

The HTML is inserted but Angular.dart seems not to do anything with it (accordion-demo-ctrl is not instantiated)


回答1:


Using the ng-include directive worked. I changed my code so that I provided the URI of the HTML fragment instead of the source itself (fetched from the server anyway).

see also my answer to How to add a component programatically in Angular.Dart? for an alternative solution



来源:https://stackoverflow.com/questions/20871982/when-i-dynamically-add-html-using-ng-bind-html-how-can-i-initiate-a-compile-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!