3
MyService.service.ts MyComponent.component.tsとMyComponent.component.htmlで使用するTypescriptで列挙しました。HTML内のTypescript列挙型に近づくことはできません
export enum ConnectionResult {
Success,
Failed
}
私は簡単にMyService.service.tsから定義列挙型の変数を取得し、比較することができます:
this.result = this.myService.getConnectionResult();
switch(this.result)
{
case ConnectionResult.Failed:
doSomething();
break;
case ConnectionResult.Success:
doSomething();
break;
}
私も* ngIf文を使用して、私のHTML内の比較のために列挙型を使用したいです:
<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>
コードはコンパイルが、ブラウザは私にエラーを与える:
Cannot read property of undefined
次のHTML指示誤差ラインで:
列挙型は次のように近づくことができない理由を誰もが知っていますか?