Can anyone help me how to call a function from external js file inside my angular2 component. Below is my code snippet, when I am trying to load the application it is throwing App is undefined error.
Here is my component code:
import { Component, OnInit, AfterContentInit } from '@angular/core';
@Component({
selector: 'test',
templateUrl: './test.html'
})
export class TestComponent implements OnInit {
constructor() { }
ngOnInit() {
}
ngAfterViewInit() {
App.handleInit();
}
}
here is my script inside app.js:
var App = function() {
var handleInit = function() {
console.log("Hello world");
};
}();
When we are calling a function inside ngAfterViewInit it is throwing App is undefined error.
We are importing app.js file inside vendor.ts and we are using webpack. Here app.js is loading fine but function was not working.
Please help us with a solution.
Thanks in advance.