2017-08-26 68 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

相關問題