title: angular- programmatically close alert when a new alert is triggered
body: <p>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.</p>
  
  <p>But there are delayed alerts also..which are triggered by a <code>setTimeout()</code>
  I'm trying to automatically close secondary alerts when this delayed alert is shown to user</p>
  
  <p>I tried to dismiss the secondary alerts like this</p>
  
  <pre><code>this.secondaryAlertVar.dismiss();
  </code></pre>
  
  <p>But it's not working.</p>
  
  <p>Here's the code</p>
  
  <pre><code>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(() =&gt; {
              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(() =&gt; {
          });
      }
  }
  </code></pre>
  
  <p><a href="https://play.nativescript.org/?template=play-ng&amp;id=dWQhV7&amp;v=529&amp;_ga=2.244207372.844477236.1570596665-623910499.1568785341" rel="nofollow noreferrer">Playground Link</a></p>