微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

属性“staticAlert”没有初始值设定项,并且在constructor.ts 中没有明确分配

如何解决属性“staticAlert”没有初始值设定项,并且在constructor.ts 中没有明确分配

import { Component,OnInit,ViewChild } from '@angular/core';

import {Subject} from 'rxjs';

import {debounceTime} from 'rxjs/operators';

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

@Component({
  selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css']
})

export class AppComponent implements OnInit {


  staticAlertClose=false;
  successMesage='';

  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) {
        this.selfClosingalert.close();
      }
    });

  }

  close(alert: Alert) {

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

  }

  reset() {

    this.alerts = Array.from(ALERTS);

  }
  title = 'blog';
}

enter code here

我启用了严格标志来帮助发现问题,但我遇到了这个问题。 我在 app.component.ts 文件中编写了这段代码,并从 https://ng-bootstrap.github.io/#/components/alert/examples 用于自动关闭警报示例

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。