Knockout's writable computed observable in AngularJS (including Ng -modle) m2
Knockout's writable computed observable in AngularJS (including Ng -modle) m1
by manoj
HTML
<div ng-app>
<div ng-controller="Ctrl">
<input type="text" ng-model="firstName"/>
<input type="text" ng-model="lastName"/>
<input type="text" ng-model="fullName"/>
<ul>
<li>{{firstName}}</li>
<li>{{lastName}}</li>
<li>{{fullName}}</li>
</ul>
</div>
</div>
JavaScript
function Ctrl($scope){
$scope.firstName = 'mano';
$scope.lastName = 'manoj';
Object.defineProperty($scope, 'fullName', {
get: function() {
return $scope.lastName ? $scope.firstName+' '+$scope.lastName : $scope.firstName;
},
set: function(value) {
// alert();
fullName = value;
}
});
// setTimeout(function(){$scope.fullName = 'Manoj kumar';}, 5000);
}