是否可以在typescript中导入string指定的类?

时间:2015-12-28 00:29:51

标签: typescript

所以我有

import { AccountData } from '../settings/AccountData/AccountData';
import { AccountDelete } from '../settings/AccountDelete/AccountDelete';
import { AccountLogin } from '../settings/AccountLogin/AccountLogin';
import { AccountPassword } from '../settings/AccountPassword/AccountPassword';
import { AddTrack } from '../settings/AddTrack/AddTrack';

import { EditUser } from '../settings/EditUser/EditUser';
import { MakePlaylist } from '../settings/MakePlaylist/MakePlaylist';
import { MakeWishlist } from '../settings/MakeWishlist/MakeWishlist';
import { ManageAdmins } from '../settings/ManageAdmins/ManageAdmins';
import { ManageEditors } from '../settings/ManageEditors/ManageEditors';
import { ManageRadiostation } from '../settings/ManageRadiostation/ManageRadiostation';
import { ManageTracks } from '../settings/ManageTracks/ManageTracks';
import { ManageUsers } from '../settings/ManageUsers/ManageUsers';

以后我有

@RouteConfig([
    { path: '/', redirectTo: ['AccountData']},
    { path: 'AccountData', name: 'AccountData', component: AccountData },
    { path: 'AccountDelete', name: 'AccountDelete', component: AccountDelete },
    { path: 'AccountLogin', name: 'AccountLogin', component: AccountLogin },
    { path: 'AccountPassword', name: 'AccountPassword', component: AccountPassword },
    { path: 'AddTrack', name: 'AddTrack', component: AddTrack },

    { path: 'EditUser', name: 'EditUser', component: EditUser },
    { path: 'MakePlaylist', name: 'MakePlaylist', component: MakePlaylist },
    { path: 'MakeWishlist', name: 'MakeWishlist', component: MakeWishlist },
    { path: 'ManageAdmins', name: 'ManageAdmins', component: ManageAdmins },
    { path: 'ManageEditors', name: 'ManageEditors', component: ManageEditors },
    { path: 'ManageRadiostation', name: 'ManageRadiostation', component: ManageRadiostation },
    { path: 'ManageTracks', name: 'ManageTracks', component: ManageTracks },
    { path: 'ManageUsers', name: 'ManageUsers', component: ManageUsers }
])
class A ...

我还要改变这个,然后添加一些东西。 是否有可能以某种方式创建和组件

var components = ['AccountData', ...]
var routes = components.map((comp) => { import comp from '../settings/' + comp + '/' + comp; return new Route(comp, comp, comp); }

@RouteConfig(routes)
class A ....

1 个答案:

答案 0 :(得分:1)

恐怕这不可能。有可能以一种使其在转换的javascript中工作的方式来实现。但是不可能让它与typescript编译器一起工作。