[英]Why is angular not parsing my template?
我有一個角度指令,在該指令加載后,我通過templateCache編譯模板。 由於某種原因,我的{{}}
會在模板中輸出,而不是被解析並替換為其各自的值。 有人知道為什么嗎?
模板看起來像這樣
<script type="text/ng-template" id="input">
<input class="cirque-input" ng-model="model" value="{{model}}" type="{{fieldtype}}" ng-change="updateForm()" />
</script>
在我的指令鏈接函數中,我得到了模板並顯示為
var tmpUrl=$templateCache.get(scope.template);
elm.html(tmpUrl);
$compile(elm.contents())(scope);
顯然我在這里做錯了,但我不知道是什么。
先編譯,然后用新的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])
我有類似的問題,但我使用replace ...您可能要嘗試:
var tmpUrl=$angular.element($templateCache.get(scope.template));
elm.append(tmpUrl);
$compile(tmpUrl)(scope);
要么
var tmpUrl=$angular.element($templateCache.get(scope.template));
elm.append(tmpUrl);
$compile(elm)(scope);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.