简体   繁体   中英

How to integrate external css and js in angular 2 and expressjs nodejs

I am new to Angular2 and NodeJs. I just wanted to know possible way to integrate external css and js in angular2 and Nodejs express app. For example I want to integrate bootstrap admin theme in Nodejs. Below is screenshot attached for the reference of app structure.

  1. Screenshot inside client folder angular2.

客户端文件夹Angular 2

  1. Screenshot for express Nodejs App.

NodeJs Express应用程序结构

Thanks. In advance.

To allow external styles to affect the content of components you can change view encapsulation (that's what prevents styles to "bleed into" components).

@Component({
    selector: 'some-component',
    template: '<div></div>',
    styleUrls: [
        'http://example.com/external.css',
        'app/local.css'
    ], 
})

Note: View encapsulation fulfills a purpose. The better way is to add styles directly to the component they should affect. ViewEncapsulation is set per component and may come handy in some situations. See also this related issue https://github.com/angular/angular/issues/5390

Example for script

    <head>
       <link href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/0.8.1/cropper.css" rel="stylesheet">
       <script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/0.8.1/cropper.js"></script>
       <script type="text/javascript">
        window.addEventListener('DOMContentLoaded', function () {
          var image = document.querySelector('#image');
          var cropper = new Cropper(image, {
            viewMode: 3,
            dragMode: 'move',
            autoCropArea: 1,
            restore: false,
            modal: false,
            guides: false,
            highlight: false,
            cropBoxMovable: false,
            cropBoxResizable: false,
            toggleDragModeOnDblclick: false,                                                  
          });
        });

      </script>

</head>

Note: the above links may vary according to JS libraries cdn links.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM