Get lightbox 2 working in Angular 2?

故事扮演 提交于 2019-12-04 09:02:45

If you are using Angular CLI, do it like you import any other external/jQuery libs.

So:

  1. npm install --save lightbox2
  2. add styles to angular-cli.json:

    "styles": [ "styles.css", "../node_modules/lightbox2/dist/css/lightbox.min.css" ],

  3. add script to angular-cli.json

    "scripts": [ "../node_modules/jquery/dist/jquery.js", "../node_modules/lightbox2/dist/js/lightbox.min.js" ],

  4. add the images to your template, e.g (using with semantic ui)

    <a href="/assets/img/flag.png" data-lightbox="image" data-title="My caption"> <img class="ui bordered small image" src="/assets/img/flag.png"> </a>

If you do not want to use jQuery seperately,

If you do not have jQuery support in your project and you do not want to use jQuery seperately, you can link to following Lightbox js file, which comes with inbuild jQuery support,

"scripts": [    
    "../node_modules/lightbox2/dist/js/lightbox-plus-jquery.js"
]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!