简体   繁体   中英

Are there certain files I should not be including in a barrel file in Angular 2 and/or does the order of imports matter?

I have a feature folder with an index.ts that looks like this:

export * from './grouping.model'
export * from './grouping.routing';
export * from './group.component';
export * from './supergroup.component';
export * from './grouping-container.component';
export * from './grouping.service';
export * from './grouping.module';

Initially I was getting this error: Can't resolve all parameters for SupergroupComponent: (?, ActivatedRoute) . I then changed the order in which these files were exported and am getting a different issue ( Unexpected value 'undefined' imported by the module 'GroupingModule' ).

If I remove the .service file from this barrel file and import it on a separate line in my component, everything works. I can't seem to find anything that talks about this issue, what should or shouldn't be included in barrel files or whether the order in which these files are exported matters.

I would assume that the order does indeed matter, but I've ordered my imports so that I import the lowest level building blocks and move up, but I still get the unresolved parameters error.

Turned out to be a pretty simple fix. The order of exports in your barrel file does matter. Start at the lowest level and work your way up and that'll take care of the issue.

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