Angular 类别';ModalDirective';不正确地实现接口';AfterViewInit';
我正在尝试向我的项目中添加模式,因此我找到了以下库: 我首先使用命令安装它:Angular 类别';ModalDirective';不正确地实现接口';AfterViewInit';,angular,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({
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();
}
import{Directive,ElementRef,Input,Renderer,AfterViewInit,OnDestroy}from
@角/芯';
从“ng2引导/ng2引导”导入{ModalModule};
@指示({
选择器:“[bsModal]”,
exportAs:'bs modal'
})
导出类ModalDirective在ViewInit、OnDestroy之后实现{
@输入()
公共设置配置(配置:ModalOptions){
this.\u config=this.getConfig(conf);
};
@Output()public onShow:EventEmitter=neweventemitter();
@Output()public onShown:EventEmitter=neweventemitter();
@Output()public onHide:EventEmitter=neweventemitter();
@Output()public onHidden:EventEmitter=neweventemitter();
}
但我有一个错误:
类“ModalDirective”错误地实现了接口“AfterViewInit”
如果使用实现AfterViewInit、OnDestroy,则需要实现接口方法
export class ModalDirective implements AfterViewInit, OnDestroy {
ngAfterViewInit() {
}
ngOnDestroy() {
}
}
如果您不需要在这些生命周期挂钩中执行任何操作,那么只需删除implements AfterViewInit,OnDestroy
另请参见:
我在文档中找到了
我认为您需要像这样添加组件:
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();
}
}
如果使用implementsOnInit,onestory方法,则应实现其接口
export class ModalDirective implements OnInit, OnDestroy {
ngOnInit() {
}
ngOnDestroy() {
}
}