Angular2 ng-bootstrap模块在组件中关闭

前端之家收集整理的这篇文章主要介绍了Angular2 ng-bootstrap模块在组件中关闭前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当输入正常时,我将通过保存关闭组件中的引导模式.
我正在使用角度v2.4.1和 ng-bootstrap 1.0.0-alpha.19

我尝试过this解决方案,但是我收到以下错误

No provider for ViewContainerRef

我试图将ViewContainerRef添加到我的module.ts但是我收到以下错误

Type ‘typeof ViewContainerRef’ is not assignable to type ‘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();
}

但这根本不起作用.我甚至没有收到错误消息.

解决方法

你必须保存对openend模态窗口的引用,以便稍后关闭它:

public mr: NgbModalRef;
...
public openModal(content: string) {
    this.mr = this.modalService.open(content);
}
...
public closeModal() {
   this.mr.close();
}

猜你在找的Angularjs相关文章