Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use variable in the path while import typescript

Is it possible to put a varible(or a const) to the path instead of writting whole path as string literal. As it seems, angular doesn't accept anything but string literal.

import aClass = require("./simpleClass"); 
import { aComponent } from aClass.myClass.Root + 'tutorial.component';

myClass:

export class myClass{    
    public static Root = "./"
}

In this example aClass.myClass.Root + 'tutorial.component' has error which was explained

like image 901
Siamak Ferdos Avatar asked Nov 28 '25 06:11

Siamak Ferdos


1 Answers

it does support dynamic imports now..

just do this

async () => {
  const { aComponent } = await import(aClass.myClass.Root + 'tutorial.component');
}

for more information

http://2ality.com/2017/01/import-operator.html

Try this

import aClass from "./simpleClass"; 
var aComponent = require(aClass.myClass.Root + 'tutorial.component').aComponent;

or

import { myClass } from './simpleClass';
const { aComponent } = require(myClass.Root + 'tutorial.component');
like image 93
Ihsan Avatar answered Nov 30 '25 19:11

Ihsan