【问题标题】:Angular : How to load external library from Bower (not available in NPM)Angular:如何从 Bower 加载外部库(在 NPM 中不可用)
【发布时间】:2018-01-08 11:16:33
【问题描述】:

我想使用我从 bower 存储库中获得的库。

由于 它在 NPM 中不可用,我想知道它如何让它工作并在我的应用程序中配置它,我的结构如下所示:

我尝试通过键入

来像处理任何其他库一样处理它
import * as DX from 'bower_components/xtrareportsjs';

我尝试将其作为脚本添加到 index.htmlangular-cli.json 脚本部分:

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

但在所有这些情况下都无法识别它。

NB:我想重新利用我的文件(像 jQuery)而不仅仅是执行它

我发现了旧的解释,关于在 system.JS 下的导入,但你可以看到这不是我的情况。

建议??

【问题讨论】:

标签: angular typescript webpack bower angular-cli


【解决方案1】:

我设法使用jquery 只需转到您的angular-cli.json file 然后在scripts 中导入所需库的路径 请检查下面的照片:

然后像这样在你的组件上使用它

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2022-12-14
    • 2016-12-28
    • 2017-01-01
    • 2022-11-11
    • 1970-01-01
    • 2018-01-30
    相关资源
    最近更新 更多