Component:
export class HomeComponent implements OnInit {
tridentData: TridentData;
constructor(private tridentServices: TridentService) { }
ngOnInit() {
this.tridentServices.getTridentData()
.subscribe(
(data: TridentData) => {
this.tridentData = data;
}
)
}
}
HTML:
<h1>{{ tridentData }}</h1> <---results in undefined
The Problem:
I am calling getTridentData() (A GET request, that returns json) on my tridentData object. I am having a ASYNC problem where the view loads before my tridentData object can retrieve the data the db. This results tridentData in undefined and my whole page breaks. How do I implement a loading animation and have the view wait for the data to load before popping in?
*ngIf="data"in your components template or a guard to make the router wait before adding the component until the data becomes available.