【问题标题】:Error Ngx-Bootstrap Modal with Directives Angular 6带有指令Angular 6的错误Ngx-Bootstrap模式
【发布时间】:2019-02-19 08:24:21
【问题描述】:

core.js:1633 ERROR 错误:未捕获(承诺中):错误:模板 解析错误:没有将“exportAs”设置为“bs-modal”的指令 ("

]#staticModal="bs-modal" [配置]="{背景:'静态'}" tabindex="-1" role="dialog" aria-label"): ng:///MobileModule/PerfilConfigComponent.html@1069:34 无法绑定 'config' 因为它不是 'div' 的已知属性。 ("

<input class="text-center form-control"
               formControlName="grupos"
               pInputText
               autocomplete="off"
               type="text"
               appBlur
               [focusRemove]="true"
               placeholder="Informe os grupos de produtos"
               [pTooltip]="perfilHints?.grupos"
               tooltipPosition="top"
               [showDelay]="2000"
               [escape]="false"
               [life]="12000"
               (click)="staticModal.show()"/>

<div class="modal fade" bsModal #staticModal="bs-modal" [config]="{backdrop: 'static'}"
   tabindex="-1" role="dialog" aria-labelledby="dialog-static-name">
   <div class="modal-dialog modal-sm">
      <div class="modal-content">
         <div class="modal-header">
            <h4 id="dialog-static-name" class="modal-title pull-left">Static modal</h4>
            <button type="button" class="close pull-right" aria-label="Close" (click)="staticModal.hide()">
               <span aria-hidden="true">&times;</span>
            </button>
         </div>
      <div class="modal-body">
      This is static modal, backdrop click will not close it.
      Click <b>&times;</b> to close modal.
    </div>
  </div>
</div>

这与 ngx-bootstrap 中的示例相同。服务正常。

【问题讨论】:

  • 你使用哪个版本的 ngx-bootstrap ?
  • 您是否已将 ModalModule.forRoot() 添加到 Angular 模块的 imports 中?
  • 构造函数(私有 headerNavService: HeaderNavbarService) { setTheme('bs4'); }
  • 从 'ngx-bootstrap/modal' 导入 { ModalModule };进口:[ModalModule.forRoot()]
  • 它正在使用服务示例

标签: angular modal-dialog ngx-bootstrap


【解决方案1】:

也许你没有在你的模块中导入 ModalModule 因为 Angular 在你的 App 中没有找到任何指令 bs-modal:

ModalModule.forRoot() 添加到您的模块中。

【讨论】:

    【解决方案2】:

    我找到了问题的解决方案。我必须导入到其他模块 ModalModule。我不知道为什么,因为它是在“app.module”中导入的,与其他人共享导入。只有使用指令才会出现问题。

    【讨论】:

    • 您缺少哪些模块?你能说得更具体点吗?
    • 我在 app.module 中添加了。但是在 app 模块中,只是在另一个模块中工作的服务。我必须为每个要使用 Dialog with 指令的模块添加 ModalModule.forRoot() 。现在它就是这样工作的。
    猜你喜欢
    • 2018-05-19
    • 2019-02-12
    • 2020-10-31
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    • 1970-01-01
    相关资源
    最近更新 更多