我在src/server/js/controller.js下的js文件中有一个函数,我想在组件的ts文件中使用该API。我写了以下代码来做同样的事情,但似乎不起作用
控制器.js
const getDomainName= (hostName) => {
console.log('hostName get controller', hostName);
}
module.exports = {getDomainName};
flush-component.ts
import {getDomainName} from '../../../../server/controllers/controller.js';
@Injectable({
providedIn: 'root'
})
export class LaunchUtil {
//How to call from here
}
注意:我不应该把这个文件放在资产文件夹下,因为它是由其他JS文件引用的。
你应该像这样导出它:
const getDomainName= (hostName) => {
console.log('hostName get controller', hostName);
}
export { getDomainName }
并使用import
语法在应用程序项目中的任何位置使用它:
import { getDomainName } from '../../../../server/controllers/controller.js';