触发新警报时,以角度方式以编程方式关闭警报

编程入门 行业动态 更新时间:2024-10-21 06:12:01
本文介绍了触发新警报时,以角度方式以编程方式关闭警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两种警报-次要警报和延迟警报 首先显示辅助警报消息,用户必须单击确定"按钮将其关闭.

I have two kinds of alerts- secondary alerts and delayed alerts Secondary alert messgaes are shown at first and user has to hit OK button to close it.

但是也有延迟警报..由setTimeout()触发 当此延迟警报显示给用户时,我正在尝试自动关闭辅助警报

But there are delayed alerts also..which are triggered by a setTimeout() I'm trying to automatically close secondary alerts when this delayed alert is shown to user

我试图消除这种次要警报

I tried to dismiss the secondary alerts like this

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: "./homeponent.html", styleUrls: ['./homeponent.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尝试此操作即可实现.

Try this using rxjs you can achieve this.

import { Component, OnInit } from "@angular/core"; import * as dialogs from "tns-core-modules/ui/dialogs"; import { interval, timer } from 'rxjs'; import { takeUntil } from 'rxjs/operators' @Component({ selector: "Home", moduleId: module.id, templateUrl: "./homeponent.html", styleUrls: ['./homeponent.css'] }) export class HomeComponent implements OnInit { source = interval(0); alive = true; secondaryAlertVar: any; constructor() { const example = this.source.pipe(takeWhile(() => this.alive)); const subscribe = example.subscribe(val => { this.secondaryAlerts(function () { }, 0, "Hhmm... ", "Alert"); }); setTimeout(() => { this.alive = false; 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(() => { }); } }

更多推荐

触发新警报时,以角度方式以编程方式关闭警报

本文发布于:2023-11-27 03:48:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636452.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   方式   角度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!