K
K
Konstantin2020-09-25 18:02:28
Angular
Konstantin, 2020-09-25 18:02:28

How to create form elements based on a model?

I have a data model:

export class CustomBlockModel implements ICustomBlock {
    public gettermethod: string;
    public tag: string;
    public type: string;
    public value: any;

    constructor(public block: ICustomBlock) {
        this.gettermethod = block.gettermethod;
        this.tag = block.tag;
        this.type = block.type;
        this.value = block.value;
    }
}


Based on this data model, I want to build form elements:

for (let [key, value] of Object.entries(values)) {
            if (key !== 'block') {
                this._form.setControl(key, new FormControl(value));
            }
        }


The problem is that the constructor's block parameter also gets into the list. Because of what you have to do a check on

if (key !== 'block') {}

How can you change the data model - so that it contains nothing extra - only public fields?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2020-09-25
@Junart1

Remove public before block

R
Rerurk, 2020-09-25
@Rerurk

Edrit Madrid, your class inherited from the interface, so use this interface! What for then create it at all!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question