JSFiddle - React, Tailwind, and code Playground
HTML
<h1>Test</h1>
<ol>
<li>Using text input will update all bindings</li>
<li>After clickin on child the child container binding is updated, but the other bindings are not</li>
<li>Retyping text in the input will show that the binding on the child is detached</li>
</ol>
<div ng-app="test" ng-controller="TestCtrl">
<parent>
<child value="myObj.value"></child>
</parent>
<output>{{value}}</output>
<input type="text" ng-model="myObj.value"/>
</div>
CSS
.parent {
border: 1px solid red;
padding: 8px;
}
.child {
border: 1px solid green;
padding: 8px;
}
.container {
border: 1px solid orange;
}
.container:before {
content : 'transclude container';
}
JavaScript
function TestCtrl($scope) {
$scope.myObj = {value : '123'};
}
angular.module('test', []).
directive('parent', function () {
return {
restrict : 'E',
transclude : true,
replace: true,
template : '<div class="parent"><b>Parent</b><div ng-transclude class="container"></div></div>'
}
}).
directive('child', function () {
return {
scope : {},
replace: true,
transclude: true,
scope: {
'value' : '=value'
},
restrict : 'E',
link : function (scope, element, attrs) {
element.bind('click', function () {
scope.$apply(function () {
scope.value = '123';
})
})
},
template : '<div class="child"><i>Child : {{value}}</i><div class="container" ng-transclude></div></div>'
}
});