2014-09-19 58 views
0

我有一個角度指令,在指令加載後,我正在通過templateCache編譯模板。出於某種原因,我的{{}}正在模板中輸出,而不是被解析並替換爲各自的值。有人知道爲什麼嗎?爲什麼angular不解析我的模板?

模板看起來像這樣

<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); 

清楚我在做什麼錯在這裏顯示出來,但我可以不知道是什麼。

回答

0

編譯,然後再與新的HTML更換濾芯:

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]) 
+0

不幸的是,我仍然沒有得到填充範圍數據的handlebars元素。 – pedalpete 2014-09-22 00:26:10

0

我有一個類似的問題,但我用替換...你可能也想嘗試:

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); 
相關問題