Angular : How to load external library from Bower (not available in NPM)

限于喜欢 提交于 2019-12-12 04:38:10

问题


i wanna use a librairy which i got from a bower repo .

Since it's not available in NPM , i wanna know how may it get it work and configure it within my app , my structure looks like this :

I have tried to deal it like any other library by typing

import * as DX from 'bower_components/xtrareportsjs';

and i have tried to add it as a script in the index.html OR the angular-cli.json scripts' part:

<script src="bower_components/xtrareportsjs/report-designer.js"></script>

but that didn't recognoze it in all of those case.

NB : i wanna reutilize my file (like jQuery) not just excecute it

I found old explications , about importation under system.JS but as you can see it's not my case.

Suggestions ??


回答1:


I managed to use jquery just go to your angular-cli.json file then import path of your desired library inside the scripts Please check the photo below:

And then use it on your component like this

declare var $: any;

@Component({
    selector: 'app-navigation',
    templateUrl: './navigation.component.html',
    styleUrls: ['./navigation.component.css']
})
export class NavigationComponent implements OnInit {

     constructor(){}

     ngOnInit(){
       console.log($('#myElement'));
     }
 }


来源:https://stackoverflow.com/questions/45440350/angular-how-to-load-external-library-from-bower-not-available-in-npm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!