When using the multiple transclude component in the Angularjs application, strange behavior is observed: changes in the models of the first slot are not visible in the controller.
<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> Tell me why the binding model of the example2Model does not work, although the binding model of the example1Model works correctly?
component-template.htmlfile, but there is no file itself, the templates do not work like that ( docs.angularjs.org/api/ng/directive/script ). Replace<test-component>with a regular<div>and the model works correctly -