【发布时间】:2017-05-08 13:28:56
【问题描述】:
当输入正常时,我将通过保存关闭组件中的引导模式。 我正在使用角度 v2.4.1 和 ng-bootstrap 1.0.0-alpha.19
我尝试了this 解决方案,但出现以下错误:
没有 ViewContainerRef 的提供者
我尝试将 ViewContainerRef 添加到我的 module.ts 中,但出现以下错误:
类型“typeof ViewContainerRef”不可分配给类型“Provider”
这里是我组件中的代码:
import { Component } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: '[add-name]',
templateUrl: '../add-name.html'
})
export class MyComponent {
public errorMessage: string = '';
constructor(public modalActive: NgbActiveModal) {}
public saveNewStuff(name: string) {
this.errorMessage = '';
if (name === '' || name === undefined) {
this.errorMessage = 'some message';
} else if (this.errorMessage === '') {
this.modalActive.close();
}
}
}
我也试过像NgbModalRef一样使用
constructor(public modalRef: NgbModalRef) {}
public closeModal() {
this.modalRef.close();
this.modalRef.dismiss();
}
但这根本不起作用。我什至没有收到错误消息。
【问题讨论】:
-
您是否在您的 ngModule 中添加了 NgbModule?
-
是的,我在 @NgModule() 的导入中添加了“NgbModule.forRoot()”
标签: angular modal-dialog ng-bootstrap