How to use code to open a modal in Angular 2?

前端 未结 14 3010
天涯浪人
天涯浪人 2020-12-05 04:34

Usually we use data-target=\"#myModal\" in the

14条回答
  •  隐瞒了意图╮
    2020-12-05 04:56

    Include jQuery as usual inside script tags in index.html.

    After all the imports but before declaring @Component, add:

    declare var $: any;
    

    Now you are free to use jQuery anywhere in your Angular 2 TypeScript code:

    $("#myModal").modal('show');
    

    Reference: https://stackoverflow.com/a/38246116/2473022

提交回复
热议问题