简体   繁体   中英

Angular2 barrel from same folder

I create a barrel index.ts

    import { List } from './list';
    import { ListModule } from './list.module';
    import { ListComponent } from './list.component';
    import { ListCreateModule } from './create/list-create.module';
    import { ListCreateComponent } from './create/list-create.component';
    import { ListRoutingModule } from './list-routing.module';

export {
  List,
  ListModule,
  ListComponent,
  ListCreateModule,
  ListCreateComponent,
  ListRoutingModule,
};

I can import it this way:

import { List } from './list';

but if I am in folder list it does not work.

I tried:

import { List } from './index';

but I got an error

any idea ?

To export a module using barrel file (index.ts), you can use following code.

export * from './list';
export * from './list.module';
export * from './list.component';
export * from './create/list-create.module';
export * from './create/list-create.component';
export * from './list-routing.module';

And to import a module from same folder by using following;

import { List } from './';

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM