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

enter image description here

with following html indication error line:

enter image description here

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" 

see angular2 access global variables html template


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -