Angular 5:如何获取待导入类库的导入相关信息
Great question—this is something every Angular developer picks up as they work with different modules. Let’s break down the most reliable ways to get the exact import info you need, using your RouterModule example as a reference:
Official Angular 5 Documentation
For core Angular modules like@angular/router, the official docs are your go-to resource. Look for the "API" section of the module’s page—here you’ll find all exported symbols (like theRoutesinterface andRouterModuleclass) clearly listed alongside their import path:@angular/router. The docs also walk through configuration steps, showing exactly how to useRouterModule.forRoot()in yourimportsarray, just like you did in your example. Make sure you’re viewing the Angular 5 version of the docs, since module structures can shift between versions.Inspect the installed package’s source files
When you install a library via npm (e.g.,npm install @angular/router), it lives in yournode_modulesfolder. Navigate tonode_modules/@angular/routerand check the main entry file (usuallyindex.d.tsfor TypeScript projects). This file explicitly lists all exported members and their origins. For your example, you’ll see a line likeexport { Routes, RouterModule } from './router';which confirms exactly what to import from@angular/router.Use your IDE’s IntelliSense
Modern IDEs like VS Code are huge time-savers here. If you start typingRouterModulein yourapp.module.ts, IntelliSense will auto-suggest the import path@angular/router—just press Tab to automatically add the full import line. Hovering over an existing symbol (likeRoutes) will also show its export location, confirming you’ve got the right path.Follow official examples and guides
Angular’s official Angular 5 guides (like the Routing & Navigation guide) include complete code snippets that show the full import setup. These examples don’t just give you the import line—they also demonstrate how to add the module to your@NgModuleimports array, which is exactly what you’re doing. Trusted community tutorials will follow the same pattern, so you can copy the import structure directly.Check the library’s README or package docs
For third-party libraries (not core Angular ones), the package’s README (either innode_modulesor on npm) will almost always include import instructions. It’ll tell you which symbols to import, their path, and how to add the module to yourimportsarray if required.
By using these methods, you’ll always have the correct import info for any Angular 5 library you’re working with.
内容的提问来源于stack exchange,提问作者bellotas

