Property ‘staticAlert’ has no initializer and is not definitely assigned in the constructor.ts

  angular, angular-bootstrap, strict, viewchild
import { Component, OnInit, ViewChild } from '@angular/core';

import {Subject} from 'rxjs';

import {debounceTime} from 'rxjs/operators';

import {NgbAlert} from '@ng-bootstrap/ng-bootstrap';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']

export class AppComponent implements OnInit {


  private _success = new Subject<string>();

  @ViewChild('staticAlert', {static: false}) staticAlert: NgbAlert;

  @ViewChild('selfClosingAlert', {static: false}) selfClosingAlert: NgbAlert;

  ngOnInit(): void {

    //throw new Error('Method not implemented.');
    setTimeout(() => this.staticAlert.close(), 20000);
    this._success.subscribe(message => this.successMessage = message);
    this._success.pipe(debounceTime(5000)).subscribe(() => {
      if (this.selfClosingAlert) {


  close(alert: Alert) {

    this.alerts.splice(this.alerts.indexOf(alert), 1);


  reset() {

    this.alerts = Array.from(ALERTS);

  title = 'blog';

enter code here

I have enabled strict flag to help catch issues and I am getting this issue.
I wrote this code in app.component.ts file and got the code from
for auto close alerts example

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.