setInnerHtml 不评估 Mustache [英] setInnerHtml doesn't evaluate Mustache
问题描述
我添加了一些 HTML 内容,在我的 NgComponent 中添加了 setInnerHtml().
I add some HTML content adding setInnerHtml() inside my NgComponent.
日志显示,指令被实例化,但 {{ctrl.xxx}}
表达式没有被评估.
Logging shows, that directives are instantiated but {{ctrl.xxx}}
expressions are not evaluated.
为了设置 HTML,我使用指令派生形式 rel="nofollowng-bind-html 带有自定义 NodeValidator
和以下 value
方法.
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);
}
}
我在插入的 HTML 中还有一些 .调试器显示 ng-model 已实例化并且
getter ctrl.someValue
被调用
但输入元素没有显示返回值.
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.
当我将生成的 HTML 静态插入为 template
时,一切正常.
When I insert the generated HTML statically as template
all works fine.
如何让动态插入的 HTML 完全被 Angular 处理.
How can get dynamically inserted HTML fully processed by Angular.
推荐答案
EDIT
包 http://pub.dartlang.org/packages/bwu_angular 包含这个装饰器/指令为 bwu-safe-html
The package http://pub.dartlang.org/packages/bwu_angular contains this decorator/directive as bwu-safe-html
------
我找到了解决方案he
@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);
}
}
另见我关于如何在 Angular.Dart 中以编程方式添加组件?的完整代码
这篇关于setInnerHtml 不评估 Mustache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!