小编BHL*_*BHL的帖子

“删除”运算符的操作数必须是可选的/对象在角度 12 中可能存在“未定义”错误

所以我正在以角度创建警报服务,但无法克服此错误。我知道可以通过在 ts.config 文件中禁用严格的空检查来抑制此错误。但不想采取这种方法尝试过操作符使其成为可选,但它仍然不起作用,我不确定我是否将操作符放在正确的位置,我是角度新手,任何指导都会非常有帮助,谢谢

 alerts: Alert[] = [];

 this.alerts!.find(x => x === alert).fade = true;

Run Code Online (Sandbox Code Playgroud)

警报模型.ts

export class Alert {
   public id!: string;
   public type!: AlertType;
   public message!: string;
   public autoClose!: boolean;
   public keepAfterRouteChange!: boolean;
   public fade!: boolean;

    constructor(init?:Partial<Alert>) {
        Object.assign(this, init);
    }
}

export enum AlertType {
    Success,
    Error,
    Info,
    Warning
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述

typescript angular

2
推荐指数
1
解决办法
8378
查看次数

标签 统计

angular ×1

typescript ×1