【发布时间】:2018-11-02 14:23:25
【问题描述】:
我有一个文件,其中包含几十个 javascript 函数。我想要做的是将该文件导入 Angular 2 组件并运行在“external.js”文件中定义的 init() 函数。
import { Component, AfterViewInit } from '@angular/core';
import "../../../../assets/external.js";
@Component({
selector: 'app-component',
templateUrl: 'app.component.html'
})
export class ComponentNameComponent implements AfterViewInit {
constructor() { }
ngAfterViewInit(): void {
// invoke init() function from external.js file
}
}
external.js 是使用 import 加载的,在 ngAfterViewInit() 中,我想调用 external.js 中的 init() 函数,该函数调用该外部文件中的所有其他方法。
这是external.js的一部分:
function init() {
callFunction1();
callFunction2();
}
【问题讨论】:
标签: javascript angular