[英]Why is angular not parsing my template?
I have an angular directive where I'm compiling a template via the templateCache after the directive has loaded. 我有一个角度指令,在该指令加载后,我通过templateCache编译模板。 For some reason, my {{}}
is being output in the template instead of being parsed and replaced with their respective values. 由于某种原因,我的{{}}
会在模板中输出,而不是被解析并替换为其各自的值。 Does anybody know why? 有人知道为什么吗?
The template looks like this 模板看起来像这样
<script type="text/ng-template" id="input">
<input class="cirque-input" ng-model="model" value="{{model}}" type="{{fieldtype}}" ng-change="updateForm()" />
</script>
and in my directives link function, I get the template and display it with 在我的指令链接函数中,我得到了模板并显示为
var tmpUrl=$templateCache.get(scope.template);
elm.html(tmpUrl);
$compile(elm.contents())(scope);
clearly I'm doing something wrong here, but I can't figure out what. 显然我在这里做错了,但我不知道是什么。
Compile first and then replace element with new html: 先编译,然后用新的html替换element:
var tmpUrl=$templateCache.get(scope.template);
var compiledContents = $compile(elm.contents())(scope);
// here i'm not sure about the html method
elm.html(compiledContents);
// maybe you have to use
// elm.replaceWith(compiledContents[0])
I had a similar problem but I use replace... you may want to try: 我有类似的问题,但我使用replace ...您可能要尝试:
var tmpUrl=$angular.element($templateCache.get(scope.template));
elm.append(tmpUrl);
$compile(tmpUrl)(scope);
or 要么
var tmpUrl=$angular.element($templateCache.get(scope.template));
elm.append(tmpUrl);
$compile(elm)(scope);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.