0
I’m making a mistake of ' Cannot read Property 'razao_social' of Undefined' when I call an ngModel in my html.
I created an interface like this:
export interface IEmpresas {
nome_fantasia : string;
razao_social : string;
cnpj : string;
}
In my component, I installed the interface and created a variable with the type of my interface.
...
private empresa : IEmpresas;
...
and then, I call ngModel in html
<input type="text" [(ngModel)]="empresa.razao_social" id="razao_social">
I understand. and in this case what would be the ideal solution?
– adahox_
The ideal solution may depend on some factors. Does it make sense that the enterprise variable is empty ? Would this be a failure to request the backend ? This variable will be loaded later when the Promise receives its result ? . But you can simply initialize this variable with an empty object in your controller or just use the same safe navigation operator (?). The result will be very similar and it is a good solution, in my opinion.
– Thiago Soares