[英]How to access JS file api in angular component.ts file
I have one function in js file under src/server/js/controller.js, and I want to use that API inside component's ts file. 我在src / server / js / controller.js下的js文件中有一个函数,我想在组件的ts文件中使用该API。 I wrote the following code to do same but seems not working 我写了下面的代码做同样的事情,但似乎不起作用
controller.js controller.js
const getDomainName= (hostName) => {
console.log('hostName get controller', hostName);
}
module.exports = {getDomainName};
flush-component.ts flush-component.ts
import {getDomainName} from '../../../../server/controllers/controller.js';
@Injectable({
providedIn: 'root'
})
export class LaunchUtil {
//How to call from here
}
Note: I should not put this file under assets folder since it is referring by other JS files. 注意:我不应该将此文件放在Assets文件夹下,因为它是由其他JS文件引用的。
You should export it like this: 您应该这样导出它:
const getDomainName= (hostName) => {
console.log('hostName get controller', hostName);
}
export { getDomainName }
And use it anywhere in your application project using import
syntax: 并使用import
语法在应用程序项目中的任何位置使用它:
import { getDomainName } from '../../../../server/controllers/controller.js';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.