angular - Cannot approach Typescript enum within HTML -
i made enum typescript use in myservice.service.ts mycomponent.component.ts , mycomponent.component.html.
export enum connectionresult { success, failed } i can , compare defined enum variable myservice.service.ts:
this.result = this.myservice.getconnectionresult(); switch(this.result) { case connectionresult.failed: dosomething(); break; case connectionresult.success: dosomething(); break; } i wanted use enum comparison within html using *ngif statement:
<div *ngif="result == connectionresult.success; else failed"> <img src="../../assets/connection-success.png" height="300px" class="image-sign-style" /> </div> <ng-template #failed> <img src="../../assets/connection-failed.png" height="300px" class="image-sign-style" /> </ng-template> the code compiles browser gives me error:
cannot read property of undefined
with following html indication error line:
does know why enum cannot approached this?
the scope of template limited component instance members. if want refer needs available there
class mycomponent { connectionresult = connectionresult; } then can use
*ngif="connectionresult.success" 

Comments
Post a Comment