export interface Element {
name: string;
}
export class Room implements Element {
name: string;
type:string
}
export class Hall implements Element {
name: string;
}
and my varibale type is like below
selectedElement: Element;
now in html how can I check if the object is having property 'type' or not?
<div *ngIf="selectedElement?.type">
my div
</div>
I guess this should do what you want:
*ngIf="hasProp(selectedElement, 'type')"
hasProp(o, name) {
return o.hasOwnProperty(name);
}