Bootstrap modal: is not a function

后端 未结 13 2227
滥情空心
滥情空心 2020-12-02 17:45

I have a modal in my page. When I try to call it when the windows load, it prints an error to the console that says :

$(...).modal is not a function
         


        
13条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 18:28

    Run

    npm i @types/jquery
    npm install -D @types/bootstrap
    

    in the project to add the jquery types in your Angular Project. After that include

    import * as $ from "jquery";
    import * as bootstrap from "bootstrap";
    

    in your app.module.ts

    Add

    
    

    in your index.html just before the body closing tag.

    And if you are running Angular 2-7 include "jquery" in the types field of tsconfig.app.json file.

    This will remove all error of 'modal' and '$' in your Angular project.

提交回复
热议问题