I am currently working with Angular2 and TypeScript.
Within my app.component.ts file, I need to dynamically load script files based on the current navigator language. To achieve this, I have added the following function in my home.component.ts:
export class HomeComponent {
constructor() {
this.loadDynamicallyScript();
}
public loadDynamicallyScript() {
let node = document.createElement('script');
node.src = "../node_modules/xxxxxxxxxx/xx." + navigator.language"+".min.js";
node.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(node);
}
However, this approach is not functioning as expected. I still need to successfully load the files on demand according to the current navigator language. Does anyone have any suggestions or solutions for this issue? Thank you for any assistance provided.