#Object model use case
import { effect, model, ModelSignal } from '@angular/core';
import { objectModel } from '@agdo/object-model';
myObject = objectModel(
{
prop1: '',
prop2: 1,
prop3: true,
array: [],
propObject: {
propObject1 : '',
propObject2 : '',
propObject3 : '',
}
});
validOptions = computed(()=> {
return this.service.getValidOptions(this.myObject.prop3()));
})
constructor(){
effect(() => {
console.log(this.myObject.prop2());
console.log(this.myObject.propObject.propObject1());
});
this.myObject.subscribe((value)=>{
let variable = value; //value is the complete object
})
}
function1(){
this.myObject.prop2.set('abc'); //active the effect
}
function1(){
this.myObject() //return complete object
this.myObject.prop1 //return signal
this.myObject.prop1() //return string
this.myObject.propObject //return signal
this.myObject.propObject() //return object
this.myObject.propObject.propObject1() //return string
}
HTML
<input [(ngModel)]='myObject.prop1'> //the change actives the effect/computed
<input [(ngModel)]='myObject.propObject.propObject1'> //the change actives the effect/computed