简体   繁体   English

类“ ModalDirective”错误地实现了接口“ AfterViewInit”

[英]class 'ModalDirective' incorrectly implements interface 'AfterViewInit'

I'm trying to add a modal to my project, so I found this library : ng2-bootstrap 我正在尝试向我的项目中添加模态,所以我找到了这个库: ng2-bootstrap

I installed it first using the command : npm install ng2-bootstrap --save 我首先使用以下命令安装了它: npm install ng2-bootstrap --save

My Class looks like : 我的班级看起来像:

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();

}

But I got this Error : 但是我得到了这个错误:

class 'ModalDirective' incorrectly implements interface 'AfterViewInit'

If you use implements AfterViewInit, OnDestroy , then you need to implement the interface methods 如果使用implements AfterViewInit, OnDestroy ,则需要实现接口方法

export class ModalDirective implements AfterViewInit, OnDestroy {

  ngAfterViewInit() {
  }

  ngOnDestroy() {
  }
}

If you don't need to do anything in these lifecycle hooks, then just remove the implements AfterViewInit, OnDestroy 如果您不需要在这些生命周期挂钩中进行任何操作,则只需删除implements AfterViewInit, OnDestroy

See Also: 也可以看看:

I found in ng2-bootstrap documentation. 我在ng2-bootstrap文档中找到。

I think you need to add in your component like this: 我认为您需要像这样添加组件:

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

    // todo: change to ng2-bootstrap
    import { ModalDirective } from '../../../components/modal/modal.component';
    @Component({
      selector: 'modal-demo',
      template: template
    })
    export class ModalDemoComponent {
      @ViewChild('childModal') public childModal:ModalDirective;

      public showChildModal():void {
        this.childModal.show();
      }

      public hideChildModal():void {
        this.childModal.hide();
      }
    }

If you use implements OnInit , OnDestroy methods then you should implement its interface 如果使用实现OnInitOnDestroy方法,则应实现其接口

export class ModalDirective implements OnInit, OnDestroy {

  ngOnInit() {
  }

  ngOnDestroy() {
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM