2016-08-03 61 views
0

我有一個JS腳本文件導入到我的index.html腳本標記。我需要在頁面呈現時調用file.init()函數。有三種不同的函數根據頁面加載,所以我無法通過腳本標記加載它。如何從Angular 2組件中的外部js文件調用函數?

有誰知道我怎麼能從這個文件調用一個函數? (這是es5)我可以用hacky解決方案,因爲我最終會按照角度2的慣例重寫整個東西(超過5000行)。

回答

0
import { Component, OnInit } from '@angular/core' 
declare var myFunction.index.init:any 

@Component({...}) 

export class MyComponent { 
    myFunction.index.init:any 

    constructor() {...} 

    ngOnInit() { 
    myFunction.index.init(); 
    } 
} 
相關問題