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. I wrote the following code to do same but seems not working
controller.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
}
Note: I should not put this file under assets folder since it is referring by other JS files.
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 { getDomainName } from '../../../../server/controllers/controller.js';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.