I have an object in MainCtrl and pass it to child component with one-way binding. When I change it in child template, changed parent object in MainCtrl. Where is my problem?
(function(angular) {
'use strict';
angular.module('heroApp', []).controller('MainCtrl', function MainCtrl() {
this.hero = {
name: 'Spawn'
};
});
})(window.angular);
(function(angular) {
'use strict';
angular.module('heroApp').component('heroDetail', {
templateUrl: 'heroDetail.html',
bindings: {
hero: '<'
}
});
})(window.angular);
<div ng-controller="MainCtrl as ctrl">
<span>Parent Obejct Name: </span>{{ ctrl.hero.name }}
<br/>
<hero-detail hero="ctrl.hero"></hero-detail>
</div>
<span>Child Object Name: {{$ctrl.hero.name}}</span>
<br/>
<input type="text" ng-model="$ctrl.hero.name" />