basicly i am setting the interface data onInit of the component but inside a promise, the thing is that i get a error on the template because the IStatus is null
Use async:
Based on your description, It's not really an interface issue. You didn't get the status values from Promise yet. You can use async to solve it
status.service.ts
getStatus() : Observable<IStatus> {
return this.http.getStats(URL);
}
status.component.ts
ngOnInit() {
// it's observable
iStatus:Observalbe<IStatus> = this.statusService.getStatus();
}
In the template, you should do something like:
<p> {{ iStauts | async }} </p>
Alternativley, you can do:
<p> {{ iStatus?. fVBackward }}</p>
Use ? check the object is ready or not, it only invoke fVBackward once iStatus is available.
Interface:
What interface does is restrict the properties in your object, for instance:
export interface Person{
name: string;
age: number;
}
aPerson: Person = {name: 'Arron', age: 23}; // this is correct
anotherPerson: Person = {name: "Bill"}; // not okay, property age is missing
thatPerson: Person = {"name": "Chris", age:24, gender:"Male"}; // not okay, property gender is not declared in interface Person
nullto it?