2017-08-01 53 views
0

我想使用一個庫,我從涼亭回購。Angular:如何從Bower加載外部庫(在NPM中不可用)

由於它不具備的NPM,我想知道怎麼還可能得到它的工作和我的應用程序中配置它,我的結構是這樣的:

enter image description here

我曾嘗試通過鍵入

import * as DX from 'bower_components/xtrareportsjs'; 

對付它像任何其他圖書館,我曾試圖將其添加爲一個腳本,IND ex.html角cli.json腳本的一部分:

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

,但沒有在所有這些情況下recognoze它。

NB:我想我的再利用文件(如jQuery)不只是excecute它

我發現老吃茶,即將system.JS進口,但你可以看到它不是我的情況。

建議?

+0

你看過[全局腳本](https://github.com/angular/angular-cli/wiki/stories-global-scripts)嗎? –

回答

2

我設法利用jquery只是去scripts 內所需庫您angular-cli.json file然後導入路徑請檢查下面的照片: enter image description here

,然後用它的分量在這樣

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')); 
    } 
}