I am trying to patch a value from a subscribe method.
ngOnInit(): void {
this.store.pipe(select(fromUsuario.getUsuario))
.subscribe((res) => {
this.formUsuario.patchValue({
nome: res.nome, <-------------- Line 36
telefone_celular: res.telefone_celular,
telefone_fixo: res.telefone_fixo
});
})
}
This works very well when i come from a page to another, because the state is already there.
But, when i open direct on the url component, i am receiving an error:
core.js:5845 ERROR TypeError: Cannot read property 'nome' of null
at SafeSubscriber._next (perfil.component.ts:36)
How i can do this async at component? thanks for any answer.
if(res && res.nome){}
did the job.
The help was from the comment of @ng-suhas
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.