模块是在app.module.ts中导入的,通过在下面添加一个条目,
@NgModule({
declarations: [
AppComponent,
HomeComponent,
DirectoryComponent,
FilterPipe,
LoggingService
],
imports: [
FormsModule,
BrowserModule,
HttpClientModule,
routing
],
providers: [],
bootstrap: [AppComponent]
})但是RouterModule直接用于../src/app/app.routes.ts,如下所示,
import {Routes, RouterModule} from "@angular/router";
export const routes:Routes = [
/* Each route will be an object {}*/
{path: 'directory', component: DirectoryComponent},
{path: '', component: HomeComponent}
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes);在RouterModule中没有@NgModule(imports: [..])条目。
( 1)导入角模块有不同的方法吗?
( 2)转角模组的输入与输入打字模组有何不同?
发布于 2017-11-17 00:17:30
在您的routes.ts中,您正在创建名为routes的常量,将其赋值为RouterModule并导出它。
在您的应用程序中,您将导入routes常量,它只是对模块的引用,就像其他任何参数一样:
@NgModule(
.... imports: [
routing, // here you are using the const
],
....
)你在这条线上分配它:
export const routing: ModuleWithProviders = RouterModule.forRoot(routes);您可以使用导出的routes并在您的app.module中使用它:
@NgModule(
.... imports: [
RouterModule.forRoot(routes),
],
....第一种方法是在使用变量之前将其赋值给一个变量(好,const)。
打字本模块不同于角度模块。类型记录模块允许您在类型记录文件之间共享类型记录对象。你可以在任何地方使用它们,甚至在非角度打印文本中也是如此。它们是import { something } from 'myfile.ts',它被转移到JavaScript ES5 require语句,就像ES6导入一样。在我的经验中,没有多少人把这些称为模块。
角模是由角组件、服务、指令和管道等组成的模块块,因此编译器知道如何处理它们,您可以轻松地从它们编写角度应用程序。如果有人谈论的是棱角和模块,很可能他们谈论这些,因为类型记录模块是如此基础-每个类型记录文件将有多个导入在顶部。
发布于 2017-11-17 00:18:49
有一个条目,您只是将它命名为routing为const。所以在你的例子中,routing实际上是RouterModule.forRoot(routes);,这意味着它是RouterModule.
我想棱角小组在这里解释得很好,https://angular.io/guide/router
也没有打字模块。只有角度模块。在您的例子中,您将角模块分配给名为const routing的routing并导出它。
https://stackoverflow.com/questions/47341234
复制相似问题