setInnerHtml doesn't evaluate Mustache

[亡魂溺海] 提交于 2020-01-05 12:15:52

问题


I add some HTML content adding setInnerHtml() inside my NgComponent.

Logging shows, that directives are instantiated but {{ctrl.xxx}} expressions are not evaluated.

For setting the HTML I use a directive derived form ng-bind-html with a custom NodeValidator and the following value method.

  set value(value) {
    _element.setInnerHtml((value == null ? '' : value.toString()),
                                             validator: validator);
    _log.finest(value);
    if(value != null) {
      BlockFactory template = _compiler(_element.children, _directiveMap);
      Block block = template.bind(_injector)(_scope);
    }
  }

I have also some <input type='text' ng-model='ctrl.someValue'> in the inserted HTML. The debugger shows that the ng-model is instantiated and
the getter ctrl.someValue gets called
but the input element doesn't show the returned value.

When I insert the generated HTML statically as template all works fine.

How can get dynamically inserted HTML fully processed by Angular.


回答1:


EDIT

The package http://pub.dartlang.org/packages/bwu_angular contains this decorator/directive as bwu-safe-html

------

I found the solution here

  @NgOneWay('ac-bind-html')
  set value(value) {
    if(value == null) {
      _element.nodes.clear();
      return;
    }
    _element.setInnerHtml((value == null ? '' : value.toString()),
                                             validator: validator);
    _log.finest(value);
    if(value != null) {
      _compiler(_element.childNodes, _directiveMap)(_injector, _element.childNodes);
    }
  }

see also my answer on How to add a component programatically in Angular.Dart? for the full code



来源:https://stackoverflow.com/questions/21756959/setinnerhtml-doesnt-evaluate-mustache

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