[Fixed] How to get all variables of a class in angular

Issue

I want to get all variables of the class item, this method getItem() works, but i dont know if is the right way, because every time i call it, create another item. Can it cause performance issues? (Sorry for bad english)

export class Item {
    item_id: number;
    item_quantidade: number;
    item_unidade_medida: number;
    item_descricao: any;
    item_codigo: string;
    item_marca: string;
    item_fornecedor: string;
    item_unitario_compra: number;
    item_unitario_venda: number;
    item_parte_caminhao: string;
    item_aplicacao: string;
    item_usu_cadastro: string;
    item_usu_data_cadastro: Date;
    item_usu_alteracao: string;
    item_usu_data_alteracao: Date;
    item_status: string;

    constructor() {
    }

    public get getItem(): Item {
        return Object.assign(new Item(), this);
    }
    public set setItem(item: Item) {
        Object.assign(this, item);
    }

}

Here is the image i want to achive without issues performace! When i console.log(item.getItem); the result is what i want
enter image description here

Solution

I found what im was looking for. The solution is create a ItemController, thanks everyone!

export class Item {
    item_id: number;
    item_quantidade: number;
    item_unidade_medida: number;
    item_descricao: string;
    item_codigo: string;
    item_marca: string;
    item_fornecedor: string;
    item_unitario_compra: number;
    item_unitario_venda: number;
    item_parte_caminhao: string;
    item_aplicacao: string;
    item_usu_cadastro: string;
    item_usu_data_cadastro: Date;
    item_usu_alteracao: string;
    item_usu_data_alteracao: Date;
    item_status: string;
}

export class ItemController {
    _item: Item;

    constructor() {
        this._item = new Item();
        this.resetItem();
    }

    public get getItem(): Item {
        return this._item;
    }
    public setItem(item: Item) {
        this._item = item;
    }

}

Leave a Reply

(*) Required, Your email will not be published