从模型类中获取数据并以角度为条件

时间:2018-09-12 14:05:56

标签: angular enums

我创建了一个类型为enum的模型类

import { AlertType } from './enums/alert-type.enum';

export class AlertModel {
   constructor(
    public type: AlertType,
    public message: string
   ){}
}

枚举在其他模型类中定义

export enum AlertType {
    Success,
    Error,
    Info,
    Warning
}

我想根据此数据类型来提醒一些事情 创建了一个组件名称警报并在此处调用该模型

import { Component, OnInit } from '@angular/core';
import { AlertModel } from '../../models/alert.model';
import { AlertType } from '../../models/enums/alert-type.enum';

@Component({
  selector: 'app-alert',
  templateUrl: './alert.component.html',
  styleUrls: ['./alert.component.css']
})
export class AlertComponent implements OnInit {
alertModel = new AlertModel(
  AlertType.Success,
  'Success'
);
  constructor() { }
  ngOnInit() {
  }
}

现在我需要根据此AlertType显示它

<div *ngIf="alertModel.AlertTypeError">
  <div class="alert-wrapper error-wrapper">
    <mat-dialog-content>
        <i class="material-icons">error</i>
        <p><span>Error:</span> Incorrect Username or Password</p>
    </mat-dialog-content>
    <mat-dialog-actions>
      <button mat-button mat-dialog-close close-btn>
          <i class="material-icons">
          close
          </i>
        </button> 
    </mat-dialog-actions>
  </div>
</div>

0 个答案:

没有答案