我將文本角度嵌入到具有範圍變量的指令中... scope.htmlContent.content。在指令中我有ng-model在嵌套指令中沒有更新
template:
'''
// This updates just fine. I use it to debug so I will take this out from time to time
<p ng-bind='htmlContent.content'></p>
// ng-model htmlContent.content stays blank and does not update
<text-angular ng-model='htmlContent.content'>
</text-angular>
''',
link: function(scope, ele, attr, ctrl) {
//some code
$http({
method: 'GET'
url: 'someurl.com'
}).success(function(data,headers,config) {
// This does not update text-angular
scope.htmlContent.content = data;
// If I add this, it will error out
scope.$apply()
})
}
無論如何,ng-model沒有正確更新。只有當我明確地在某些異步fxn的鏈接函數的開始部分設置scope.htmlContent.content時,它才起作用。我怎樣才能更新ng模型?
爲http調用和tgen jnject創建一個工廠,使其進入指令 – V31
如果您更多地解釋了這一點並將其添加爲答案,我會接受它。 –
你在範圍上遇到什麼錯誤。$ apply? – V31