我正在尝试学习 AngularJS,并且正在尝试动态编译一些 DOM 元素......
我已经尝试过演示:
try {
var templateHTML = angular.element('<p>{{total}}</p>'),
scope = ....;
var clonedElement = $compile(templateHTML)(scope, function(clonedElement, scope) {
//attach the clone to DOM document at the right place
});
//now we have reference to the cloned DOM via `clone`
} catch (ex) {
alert(ex.message);
}
但我得到的只是“$compile 未定义”
HELP!
在指令中使用 $compile 的示例代码。基本上继续并首先将元素附加到 DOM(可能希望使其不可见),然后使用查找器运行编译。正如 rtcherry 提到的,应该注入 $compile。
//
componentModule.directive('getCompilerWk', function($compile) {
return {
restrict: 'A',
link: function(scope, elm, attr) {
elm.click(function(){
$(body).append(templateHTML);
$compile($(body).find('p'))(scope);
})
}
};
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)