Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add external javascript library in a gateway project

I'm trying to add Simpl5 javascript library to my gateway unsuccessfully. I've put SIPml-api.js and SIPml.js in webapp/content/scripts folder.

In .angular-cli.json I've update scripts array like this :

    "scripts": [
        "content/scripts/SIPml-api.js",
        "content/scripts/SIPml.js"
    ]

I've then try to call SIPml in component like this :

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

}

I getting ERROR ReferenceError: SIPml is not defined in the console.

Can someone help please ?

like image 784
freemanpolys Avatar asked Aug 26 '17 18:08

freemanpolys


People also ask

Can JavaScript in seperate file?

You can keep the JavaScript code in a separate external file and then point to that file from your HTML document.

What is External JavaScript file?

External JavaScript is when the JavaScript Code(script) is written in another file having an extension . js and then we link this file inside the <head> or<body> tag of our HTML file in which the code is to be added.


1 Answers

JHipster does not fully supports angular cli as @GaëlMarziou already mentioned in comments.

The original idea of supporting the CLI was only for code generation.

So any .angular-cli.json modificatons won't have any effect as JHipster is using its own build/serve chain (have a look in to package.json custom scripts, they are not based on ng serve/build, etc ) check this issue discussion for more details.

You need to reference your custom css and js in vendor.ts then when you run npm run serve you will see the result.

like image 75
angularrocks.com Avatar answered Oct 13 '22 02:10

angularrocks.com