Is there a way to avoid console errors from undefined objects?
Imagine I have the following code:
name : string;
constructor(private data: DataService) {
this.data.name.subscribe(res => this.name = res);
}
In my HTML, I have this:
<p> {{name}}</p>
Upon loading the page, I receive an error stating _co.name
is not defined, but the value of name
still appears on the page. It seems like the component is loading before receiving the data.
What would be the most effective approach to prevent this issue?
I've heard using ngIf
to check if it's not null
could work as a solution. Alternatively, I came across something called Resolve.