2017-08-26 79 views
4

我正在尝试向我的网关添加Simpl5 JavaScript库失败。 我把SIPml-api.jsSIPml.jswebapp/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未在控制台中定义

有人可以帮忙吗?

+0

我认为你的函数应该叫做'AfterViewInit' –

+0

。JHipster webpack的配置不使用.angular-cli.json。您是否尝试将SIPml * .js复制到webapp/app文件夹,然后按照https://stackoverflow.com/questions/38318542/how-to-use-javascript-in-typescript –

+0

我试图复制SIPml * .js到webapp /应用程序,但我仍然没有定义SIPml。我还添加了“allowJs”:对tsconfig.json是true。 – freemanpolys

回答

1

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了解更多详情。

您需要在​​中引用您的自定义cssjs,然后在运行npm run serve时会看到结果。

+0

我读过讨论,但我仍然可以找出如何去做。 – freemanpolys

+0

@freemanpolys刚更新了答案。很抱歉,讨论并不意味着要展示如何导入自定义资源,它更多的是为什么角度cli得不到完全支持。 – Kuncevic

+1

谢谢@Kuncevic,vendor.ts是包含外部css和js的地方。 – freemanpolys

相关问题