I try to dynamic create variables in class to store values and use it in ngModel and other placese. I know, that I can assign value to variables in ngOnInit() like this
export class Component implements OnInit{
name: string;
ngOnInit(){
this.name = 'John Doe';
}
}
But I have some problem - I get my fields from server API and don't know what and how many items I get. I can only parsing server response and assign value to new variables after get it.
I can't do it like this (TS2540: Cannot assign to 'name' because it is a constant or a read-only property.)
export class Component implements OnInit{
ngOnInit(){
name = 'John Doe';
}
}
How can I assign new fields to my class in ngOnInit() or maybe in other place? (I think I can do it in constructor, but documentation say i shouldn't use it with Observable call to API and other difficult things)