工作,我在這勢必模型name
控制器已經一個文本框。還有的控制器內的指令和有指令內的另一個文本框被綁定到相同型號name
:雙向綁定不與指令範圍transcluded
<div class="border" ng-controller="editCtrl">
Controller: editCtrl <br/>
<input type="text" ng-model="name" />
<br/>
<tabs>
Directive: tabs <br/>
<input type="text" ng-model="name"/>
</tabs>
</div>
mod.directive('tabs', function() {
return {
restrict: 'E',
transclude: true,
template:
'<div class="border" ng-transclude></div>',
};
});
當你在外部文本框中輸入的東西會反映在內部文本但如果您在內部文本框中輸入某些內容,它將停止工作,即兩個文本框不再反映相同的值。
見例如在:http://jsfiddle.net/uzairfarooq/MNBLd/
我也使用兩種方式結合ATTR(scope: {name: '='}
)嘗試,但它提供了語法error.And使用scope: {name: '@'}
具有同樣的效果。
任何幫助將不勝感激。
除了接受的答案,this article真的幫助我瞭解兒童scpoes原型繼承。我強烈建議任何有問題的人都可以仔細閱讀。
無關,但我不會使用無效的HTML元素(「標籤」) –
@ajkochanowicz這是沒有錯的,除非你想要支持那個古老而討厭的IE。儘管如此,還是有解決方法。 – Frizi