Javascript 无法从TS文件访问外部JS文件的函数
我在外部JS文件中定义了一个函数。我无法在home.page.ts文件中使用它。它将错误显示为TypeError:无法读取未定义的属性'functionName' index.htmlJavascript 无法从TS文件访问外部JS文件的函数,javascript,node.js,angular,typescript,ionic-framework,Javascript,Node.js,Angular,Typescript,Ionic Framework,我在外部JS文件中定义了一个函数。我无法在home.page.ts文件中使用它。它将错误显示为TypeError:无法读取未定义的属性'functionName' index.html <body> <app-root></app-root> <script src="assets/multiLayerSource.js"></script> </body> 主页.ts var multiLayerSour
<body>
<app-root></app-root>
<script src="assets/multiLayerSource.js"></script>
</body>
主页.ts
var multiLayerSource;
var layersHT = [];
function SetLayerHT(arglayersHT) {
layersHT = arglayersHT;
}
import { Component } from '@angular/core';
import { OnInit, Renderer, ViewChild } from '@angular/core';
declare var multiLayerSource: any;
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
layersHTP: any = [];
constructor() {}
ngOnInit() {
this.layersHTP.push( 'a', 'b', 'c', 'd' );
multiLayerSource.SetLayerHT(this.layersHTP);
}
}
尝试访问SetLayerHT()时显示错误。
错误是:
TypeError: Cannot read property 'SetLayerHT' of undefined.
请帮助。将js文件移动到资产文件夹,然后在代码中执行以下操作
import 'assets/js/multiLayerSource';
declare var SetLayerHT: any;
ngOnInit() {
this.layersHTP.push( 'a', 'b', 'c', 'd' );
SetLayerHT(this.layersHTP);
}