admin管理员组文章数量:1356056
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 + 'tutorialponent';
myClass:
export class myClass{
public static Root = "./"
}
In this example aClass.myClass.Root + 'tutorialponent'
has error which was explained
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.ponent';
myClass:
export class myClass{
public static Root = "./"
}
In this example aClass.myClass.Root + 'tutorial.ponent'
has error which was explained
- "has error which is explained" what error? – evolutionxbox Commented Apr 18, 2017 at 9:39
- Compiler says that path should be literal string – Siamak Ferdos Commented Apr 18, 2017 at 9:40
-
aClass.myClass.Root
isundefined
... Instead useaClass.Root
? Although I still don't think that will work. – evolutionxbox Commented Apr 18, 2017 at 9:41
1 Answer
Reset to default 7it does support dynamic imports now..
just do this
async () => {
const { aComponent } = await import(aClass.myClass.Root + 'tutorial.ponent');
}
for more information
http://2ality./2017/01/import-operator.html
Try this
import aClass from "./simpleClass";
var aComponent = require(aClass.myClass.Root + 'tutorial.ponent').aComponent;
or
import { myClass } from './simpleClass';
const { aComponent } = require(myClass.Root + 'tutorial.ponent');
本文标签: javascriptHow use variable in the path while import typescriptStack Overflow
版权声明:本文标题:javascript - How use variable in the path while import typescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743996088a2573014.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论