【问题标题】:How do I call a function from an external js file in an Angular 2 component? [duplicate]如何从 Angular 2 组件中的外部 js 文件调用函数? [复制]
【发布时间】:2016-08-03 08:44:20
【问题描述】:

我的 index.html 中有一个带有脚本标签的 JS 文件。我需要在页面呈现时调用 file.init() 函数。根据页面加载三种不同的功能,因此我无法通过脚本标签加载它。

有谁知道我如何从这个文件中调用一个函数? (它是 es5)我可以接受一个 hacky 解决方案,因为我最终会按照 angular 2 约定重写整个事情(超过 5000 行)。

【问题讨论】:

    标签: javascript node.js mongodb express angular


    【解决方案1】:
    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();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多