【问题标题】:How to fix' $ 'modal bootstrap is not defined?如何修复'$'modal bootstrap未定义?
【发布时间】:2020-03-04 03:34:31
【问题描述】:

我想使用模态弹出窗口。它正在向我显示 ng ///appmodule/appcomponent host.ngfactory.js sm 这个页面。(它是空的)

user.html

<div >
    <button data-toggle="modal" mat-raised-button="primary" (click)=display()>Display Student</button>
</div>
<app-display></app-display>

user.ts

declare var $:any;
(<any>$('#modal-display')).modal('show');

display.html

<div class="modal fade" id='modal-display'>
    <p>list works!</p>
</div>

它应该会弹出另一个 html 的窗口。但它向我显示错误是'$ 未定义'。并显示这个空页面 ng ///appmodule/appcomponent host.ngfactory.js sm

【问题讨论】:

  • 如果你使用的是$,你需要安装jQuery。但不鼓励这样做,因为您已经在使用角材料。
  • 你永远不应该,永远不要永远将 Jquery 与 angular 一起使用。
  • 好的,那我应该使用 MatDialog 吗?
  • @Minakshi 是的,有很多选项,比如 Primeng 的对话框、垫子对话框。你可以使用任何一个。
  • 或者......你可以只使用引导程序进行角度。 ng-bootstrap.github.io/#/home 只是另一种选择

标签: html angular twitter-bootstrap typescript


【解决方案1】:

您可能面临的问题是因为您尚未在应用程序中安装 jQuery 包。运行命令来安装它 -

npm i jquery --save

PS:不建议/不推荐将 jQuery 与 Angular 一起使用,有很多选项,例如 Primeng 的对话框、Mat 对话框、ng-bootstrap 对话框等,您可以使用任何一种。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 2019-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多