Below is my object:
$scope.obj = {
name: null,
child: { name : name}
};
<input type="text" ng-model="obj.name" />
What I am trying to do is when I will have latest value in my obj.name property it should automatically get reflected in obj.child.name property.
I would always like to use updated value and everywhere I am using obj.child.name property only so later on if I forgot to assign like below:
$scope.obj.child.name = $scope.obj.name
then it will always use old value and I don't want to do this at so many place. So I want this process to be automated like whenever name $scope.obj.name will be updated; it should automatically update $scope.obj.child.name.
But with above code I am getting error: name is undefined.
Why is the above declaration not possible and how to achieve this?
namevariable in the given context. You can create a function and return the value ofnamefrom it.child: function() { return this.name; }.