我已經根據HTML <p>
標籤做了一個非常簡單的段落指令。帶ng-transclude的角度指令
angular.module('myApp').directive('paragraph', function() {
return {
restrict: 'E',
transclude: true,
controller: function() {
var vm = this;
vm.text = "Paragraph text from controller"
},
controllerAs: 'ParagraphViewModel',
template: '<p ng-transclude>{{ParagraphViewModel.text}}</p>'
}
});
我使用的指令在我的HTML如下:
<paragraph>This is a very simple paragraph</paragraph>
<paragraph></paragraph>
而且我有我這勢必ParagraphViewModel.text
輸入。
<input type="text" ng-model="ParagraphViewModel.text">
的問題是,當我更改輸入,預期第二<paragraph>
變化,但第一批價值沒有。
請檢查this JSBin以查看它的行動。
那麼,有沒有解決方案爲了這? – sadrzadehsina
解決方案是什麼? :)它應該表現這種方式。你試圖達到什麼樣的行爲? –
@丹尼斯明白了。使用ng-transclude時,Angular會替換你的標籤。 –