如何在网关项目中添加外部JavaScript库
我正在尝试向我的网关添加Simpl5 JavaScript库失败。 我把SIPml-api.js和SIPml.js在webapp/content/scripts文件夹中。如何在网关项目中添加外部JavaScript库
在.angular-cli.json我已经更新脚本数组是这样的:
"scripts": [
"content/scripts/SIPml-api.js",
"content/scripts/SIPml.js"
]
然后我尝试调用SIPml在组件这样的:
import { Component, OnInit } from '@angular/core';
declare var SIPml: any;
。
ngOnInit() {
SIPml.setDebugLevel((window.localStorage && window.localStorage.getItem('org.doubango.expert.disable_debug') === 'true') ? 'error' : 'info');
}
我得到错误的ReferenceError:SIPml未在控制台中定义。
有人可以帮忙吗?
JHipster
并未完全支持角度cli,因为@GaëlMarziou已在评论中提及。
The original idea of supporting the CLI was only for code generation.
因此,任何.angular-cli.json
modificatons不会有同样JHipster
正在使用自己build/serve
链任何影响(在对package.json
自定义脚本一看,他们是不是基于ng serve/build
等)检查this issue discussion了解更多详情。
您需要在中引用您的自定义css
和js
,然后在运行npm run serve
时会看到结果。
我读过讨论,但我仍然可以找出如何去做。 – freemanpolys
@freemanpolys刚更新了答案。很抱歉,讨论并不意味着要展示如何导入自定义资源,它更多的是为什么角度cli得不到完全支持。 – Kuncevic
谢谢@Kuncevic,vendor.ts是包含外部css和js的地方。 – freemanpolys
我认为你的函数应该叫做'AfterViewInit' –
。JHipster webpack的配置不使用.angular-cli.json。您是否尝试将SIPml * .js复制到webapp/app文件夹,然后按照https://stackoverflow.com/questions/38318542/how-to-use-javascript-in-typescript –
我试图复制SIPml * .js到webapp /应用程序,但我仍然没有定义SIPml。我还添加了“allowJs”:对tsconfig.json是true。 – freemanpolys