它可以是配置的行为和预期的。但是这里有太多的未知数,无法准确地说出。首先,您将外部*ngIf
设置为staticAlertClosed
- 单击时将其设置为 true。所以它会“永远”保持关闭 - 或者直到页面重新加载。如果要显示新警报,则必须再次将其设置为 false。
你已经在这样做了吗?如果不是,下面是它在示例组件中的外观:
const DEFAULT_ALERT_TIMEOUT = 3000; // expire message after 3 seconds.
export class MyComponent implements NgOnInit {
message: string;
type: string;
staticAlertClosed = true; // do not show by default
constructor(private messages: MessagesService) {} // inject a service which provides fresh messages
ngOnInit() {
// subscribe to the new messages
this.messages.alerts$.subscribe(alert => {
// new message
this.message = alert.message;
this.type = alert.type;
this.staticAlertClosed = false;
// auto-close if not error
if (alert.type !== 'error') {
setTimeout(() => this.staticAlertClosed, DEFAULT_ALERT_TIMEOUT)
}
});
另一种方法是跟踪消息并独立显示/隐藏每个消息。您可以在ng-bootstrap 页面上看到这些示例。