【问题标题】:There is no directive with "exportAs" set to "bs-modal"没有将“exportAs”设置为“bs-modal”的指令
【发布时间】:2017-01-23 21:53:23
【问题描述】:

我想按照

的示例将子模式集成到我的项目中
https://valor-software.com/ng2-bootstrap/#/modals#static

但我得到一个异常显示如下:

没有将“exportAs”设置为“bs-modal”的指令。我在谷歌上搜索并在此链接上找到了答案,但它不起作用。

https://github.com/valor-software/ng2-bootstrap/issues/667#issuecomment-235204534 

当我遵循他的解决方案时,这条线不起作用:

从 'ng2-bootstrap/ng2-bootstrap' 导入 {MODAL_DIRECTIVES, BS_VIEW_PROVIDERS,ModalDirective};

有人可以帮忙吗?谢谢。 我的项目正在使用:

 "ng2-bootstrap": "^1.2.4"
 "@angular/common": "2.4.3",
 "@angular/compiler": "2.4.3",
 "@angular/core": "2.4.3",
 "@angular/forms": "2.4.3",
 "@angular/http": "2.4.3",

【问题讨论】:

  • 如果有人 valor 软件提供有关如何正确执行此操作的教程会很好,因为当您尝试在现实世界场景中实现它们时,这些模态是一个完整的球痛......跨度>
  • 是的,我同意你的看法。谢谢

标签: ng2-bootstrap


【解决方案1】:

我也使用了来自同一个链接的同一个模态。所以我得到了完全相同的错误。解决方案对我来说是这样的: 您应该将import {ModalModule} from 'ng2-bootstrap/modal' 行添加到您的 app.module.ts 然后像下面这样导入它。只需确保使用 forRoot()。 没有它,您将不断出错。

 @NgModule({
      imports: [
        ModalModule.forRoot()
      ]

之后,您还需要对 yourpage.module.ts 执行此导入操作。 该解决方案对我有用,我也希望对你有用。

注意:顺便说一下,这是我的版本:

  • “ng2-bootstrap”:“^1.3.3”,
  • "@angular/common": "2.4.8",
  • "@angular/compiler": "2.4.8",
  • “@angular/core”:“2.4.8”,
  • “@angular/forms”:“2.4.8”,
  • “@angular/http”:“2.4.8”,

【讨论】:

    【解决方案2】:

    此类问题可能由以下两种情况之一引起: 1. 您的组件中可能缺少这一行 @ViewChild('childModal') public childModal: ModalDirective; 2. 您可以在模块声明中省略导入

        import {ModalModule} from "ng2-bootstrap";
    
            @NgModule({
          imports: [
                ModalModule.forRoot()
       ],
       declarations: [],
       providers: []
       })
       export class MyModule{}
    

    【讨论】:

      猜你喜欢
      • 2017-08-10
      • 1970-01-01
      • 2018-08-05
      • 2018-07-12
      • 2019-06-19
      • 2017-10-02
      • 1970-01-01
      相关资源
      最近更新 更多