I am encountering a situation where I have an object containing both an 'id' and 'name' property, structured like this:
function format(id){
return '(' + id + ')';
}
function MyObject(id){
this.id = id;
this.text = format(id);
}
In my Angular application, I am trying to display this data in the following HTML code:
<input ng-model="myObject.id" type="text">{{myObject.text}}
Currently, when I update the 'id', the 'text' does not change accordingly. To achieve this, I must use 'ng-change' to track changes in the object's id property. However, I believe there should be a more automatic way to handle this in Angular.
My inquiry is whether it is possible to automate the binding of changes in the object property to the function call without relying on 'ng-change'?
P.S. Additionally, as I have an array of such objects, I would prefer avoiding the usage of $scope.$watch()
:)