【发布时间】:2019-10-10 13:15:39
【问题描述】:
我有两种警报 - 辅助警报和延迟警报 次要警报消息首先显示,用户必须点击确定按钮才能关闭它。
但也有延迟警报..由setTimeout() 触发
我正在尝试在向用户显示此延迟警报时自动关闭辅助警报
我试图关闭这样的辅助警报
this.secondaryAlertVar.dismiss();
但它不起作用。
这是代码
import { Component, OnInit } from "@angular/core";
import * as dialogs from "tns-core-modules/ui/dialogs";
@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html",
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
secondaryAlertVar: any;
constructor() {
this.secondaryAlerts(function () { }, 0, "Hhmm... ", "Alert");
setTimeout(() => {
this.delayedAlertBox("All other alerts should close automatically when this triggered");
}, 10000);
}
ngOnInit() {
}
secondaryAlerts(callback, mode, message, title): any {
this.secondaryAlertVar = dialogs
.alert({
title: title,
message: message,
cancelable: false,
okButtonText: "OK"
})
.then(callback);
}
delayedAlertBox(message) {
this.secondaryAlertVar.dismiss();
var options = {
title: "Delayed Alert",
message: message,
okButtonText: "Ok",
cancelable: false,
};
dialogs.alert(options).then(() => {
});
}
}
【问题讨论】:
-
您应该为此使用
rxjs。如果你这样做了 - 你可以使用observable.pipe(takeUntil(delayedAlertBoxState$))并玩弄它。 :) -
很抱歉,我不使用 nativescript,但我认为这个对话框可以生成
promise,您应该可以使用from连接到它。 -
从 rxjs 获取 BehaviorSubject,观察延迟警报。辅助警报关闭事件应该订阅延迟警报 observable。它会起作用,但需要正确思考和使用它。
-
在您的游乐场链接中,您似乎在点击事件时使用了一些 alert()。它在哪里声明
-
` dialogs.alert(options).then(() => { this.secondaryAlertVar.dismiss(); });` 这行得通吗?
标签: angular rxjs angular2-nativescript