Im looking for a way to access a variable from external js file which i included in assets/data folder
below is what i tried
placed test.js
This solution only worked for me
Put the import js in
src/index.html
header tag, before thebuild/polyfills.js
andbuild/main.js
(they are in body tag);
Example : I created a file src/assets/test.js
with a var testvar
, imported in src/index.html
and then in src/app/app.component.ts
declared declare var testvar;
.
test.js
var testvar = "Hello from external js";
index.html
...
//here, not in body
...
app.componet.ts
declare var testvar;
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
constructor(private statusbar : StatusBar, splashScreen: SplashScreen) {
alert(testvar);
...