这是一个关于imports (TypeScript)和NgModule-Imports的一般性问题。例如,您需要在一些您自己的ReactiveFormsModule中使用NgModules。
我想是的,因为你需要打字模块来处理它。
我不确定,因为有时我读到“导入你的MainModule”.但是我如何将它传递给另一个NgModules呢?
发布于 2021-08-10 08:04:38
当我构建角项目时,我只创建了几个组件&服务,以便将项目分离为单元,但是只使用了一个@NgModule类。
然后主模块中使用的导入/导出在所有子组件中都可用,因此不需要再次导入/导出它们。
理论上,我认为您可以创建多个模块,但这取决于您的需要,例如,为路由创建一个单独的模块。
发布于 2021-08-10 10:22:40
看看文档 (嗯,在我看来,这个解释不是很好)
其思想是,当您在模块中声明组件时,该组件只能访问在此模块中声明的指令/组件,如果模块导入其他组件,则访问该模块中声明的组件。所以是的,您需要在声明使用ReactiveFormsModule的组件的所有模块中导入ReactiveFormsModule。
在模块中,把它看作是不知道它是否被导入的“东西”。
Tipical您有一个utilsModule,它包含一些在应用程序中使用的组件,因此在声明中将其导出:
@NgModule({
imports:[CommonModule]
declarations: [ ErrorComponent,ConfirmComponent],
exports:[ErrorComponent,ConfirmComponent]
})
export class UtilModule { }
}还有一个模块用户声明两个组件,您的组件使用ReactiveFormsModule
{
@NgModule({
imports:[CommonModule,ReactiveFormsModule,UtilsModule]
declarations: [ UserListComponent,UserEditComponent],
//you not use export because UserListComponent and UserEditComponent
//are not use outside this module
})
export class UserModule { }
}在UserEditComponent中,你有,例如。
import {FormGroup,FormControl} from '@angular/forms'
import {ErrorComponent} from '../utils/utils.module'https://stackoverflow.com/questions/68722434
复制相似问题