我正在 Angular 项目中将 Taiga UI 从 v3 迁移到 v4。如果我想将 TuiNotification 用于像 TuiNotification.Warning 这样的常量,那么在 v4 中应该如何使用它呢?这在 v3 中是可以的,但它已经被弃用了,他们建议使用同一个包中的 TuiNotificationT,但在 v4 中不存在它。
以下是当前代码的示例:
...
import { TuiNotification } from '@taiga-ui/core';
...
@Injectable()
export class SomeInputService extends RxState<{
}> {
constructor(
private notifications: TuiAlertService
) {
super();
this.doSomething();
}
private doSomething() {
if (!something) {
return this.showNotification(
marker('Not working'),
marker('Wrong file'),
**TuiNotification.Warning**
);
}
else {
return this.showNotification(
marker('Some error'),
text ?? '',
**TuiNotification.Error**
);
}
}
private showNotification(
title: string,
text: string,
status: TuiNotification
) {
const label = this.transloco.translate(title);
const message = this.transloco.translate(text);
this.hold(
this.notifications.open(message, { status, label, autoClose: 10000 })
);
}
}
我得到的错误是
Property 'Warning' does not exist on type 'typeof TuiNotification'.ts
在 v4 中
TuiNotification
已从 变为enum
组件TuiNotification
。notification.directive.ts - 源代码
此外,当我们触发
.open
方法时,我们必须订阅它,以便弹出窗口打开。error
尽管它不存在于源代码类型中,但外观似乎也有效。因此,您需要根据字符串值进行配置。您可以使用以下列表中的值,它就可以正常工作。
appearance.options.ts - 源代码
完整代码:
Stackblitz 演示