我正在尝试在2-3秒内隐藏清晰度警报,但是使用此代码t不会显示,我也不明白。
import { Observable} from 'rxjs/Rx';
public timerAlert: boolean = false;
ngOnInit() {
let timer = Observable.timer(2000, 3000);
timer.subscribe( () => {
this.timerAlert = true; --> with this line My alert doesn't show.
});
}
HTML
<clr-alert [(clrAlertClosed)]="timerAlert" [clrAlertClosable]="false" [clrAlertType]="'alert-danger'" *ngIf="errorServer">
<clr-alert-item>
<span class="alert-text">
{{ this.myMessage.message }}
</span>
</clr-alert-item>
</clr-alert>
[clrAlertClosable]="false" for hidde 'x' in Alert.
[(clrAlertClosed)]="timerAlert" with this, I should show or not the alert.
答案 0 :(得分:0)
我可以解决... 50%
import { Observable } from 'rxjs/Rx';
public timerAlert: boolean = false;
ngOnInit() {
let timer = Observable.timer(10, 8000);
this.timerAlerts(timer);
}
private timerAlerts(timer) {
timer.subscribe(() => {
if (this.errorServer || this.confirmedServer) {
this.timerAlert = true; // firstTrue
this.timerAlert = false;
this.errorServer = false;
this.confirmedServer = false;
}
});
}
唯一的问题是...如果您确实要插入o进行快速修改,则时间将不会开始, 也就是说,如果您在7秒钟内修改了某些内容,则消息确认仅为1秒...
html
<clr-alert [(clrAlertClosed)]="timerAlert" [clrAlertClosable]="false" [clrAlertType]="'alert-danger'" *ngIf="errorServer">
<clr-alert-item>
<span class="alert-text">
{{ this.myMessage.message }}
</span>
</clr-alert-item>
</clr-alert>
<clr-alert [(clrAlertClosed)]="timerAlert" [clrAlertClosable]="false" [clrAlertType]="'alert-success'" *ngIf="confirmedServer">
<clr-alert-item>
<span class="alert-success">
{{ this.myMessage.message }}
</span>
</clr-alert-item>
</clr-alert>
我该如何解决?