class'ModalDirective'错误地实现接口'AfterViewInit'

Mou*_*ssi 1 ng2-bootstrap angular

我正在尝试为我的项目添加一个模态,所以我找到了这个库:ng2-bootstrap

我首先使用命令安装它: npm install ng2-bootstrap --save

我的班级看起来像:

import { Directive, ElementRef, Input, Renderer, AfterViewInit, OnDestroy } from 
@angular/core';
import { ModalModule } from 'ng2-bootstrap/ng2-bootstrap';

@Directive({
  selector: '[bsModal]',
  exportAs: 'bs-modal'
})
export class ModalDirective implements AfterViewInit, OnDestroy {
  @Input()
  public set config(conf:ModalOptions) {
    this._config = this.getConfig(conf);
  };

  @Output() public onShow:EventEmitter<ModalDirective> = new EventEmitter();
  @Output() public onShown:EventEmitter<ModalDirective> = new EventEmitter();
  @Output() public onHide:EventEmitter<ModalDirective> = new EventEmitter();
  @Output() public onHidden:EventEmitter<ModalDirective> = new EventEmitter();

}
Run Code Online (Sandbox Code Playgroud)

但我得到了这个错误:

class 'ModalDirective' incorrectly implements interface 'AfterViewInit'

Pau*_*tha 6

如果使用implements AfterViewInit, OnDestroy,则需要实现接口方法

export class ModalDirective implements AfterViewInit, OnDestroy {

  ngAfterViewInit() {
  }

  ngOnDestroy() {
  }
}
Run Code Online (Sandbox Code Playgroud)

如果您不需要在这些生命周期钩子中执行任何操作,那么只需删除 implements AfterViewInit, OnDestroy

也可以看看: