0
我在Angularjs中使用多個transclude組件的奇怪行爲: 第一個slot模型中的更改在控制器中不可見。在Angularjs中使用多個transclude組件的奇怪行爲1.6.1
<div ng-app="myApp" ng-controller="testController">
<script type="text/ng-template" id="component-template.html">
<div style="color:red;" ng-transclude="heading">
</div>
<div style="color:blue;" ng-transclude="body">
</div>
</script>
Example1
<input ng-model="example1Model"/>
<test-component>
<panel-heading>
Example2
<input ng-model="example2Model"/>
</panel-heading>
<panel-body>
Example1Result:{{example1Model}}<br/>
Example2Result:{{example2Model}}
</panel-body>
</test-component>
</div>
<script>
angular.module("myApp", [])
.controller("testController", function ($scope, $location) {
})
.component("testComponent", {
templateUrl: "component-template.html",
transclude: {
heading: "panelHeading",
body: "panelBody"
},
controller: function ($scope, $element, $attrs) {
this.$doCheck = function() {
//do anything
}
}
});
</script>
現在,如果你嘗試測試它在此的jsfiddle:https://jsfiddle.net/Lpveophe/1/
爲什麼綁定模型example2Model
沒有工作? 但是example1Model
綁定模型正常工作。
它的工作原理!謝謝! –