@agdo/object-model
TypeScript icon, indicating that this package has built-in type declarations

1.2.34 • Public • Published

#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

Readme

Keywords

none

Package Sidebar

Install

npm i @agdo/object-model

Weekly Downloads

21

Version

1.2.34

License

MIT

Unpacked Size

3.09 kB

Total Files

4

Last publish

Collaborators

  • andrei_agdo