加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:54:38 所属栏目:安全 来源:网络整理
导读:当输入正常时,我将通过保存关闭组件中的引导模式. 我正在使用角度v2.4.1和 ng-bootstrap 1.0.0-alpha.19 我尝试过this解决方案,但是我收到以下错误: No provider for ViewContainerRef 我试图将ViewContainerRef添加到我的module.ts但是我收到以下错误: Ty
当输入正常时,我将通过保存关闭组件中的引导模式.
我正在使用角度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();
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读