Angular FormsModule在不同于App Module的模块中工作不正常
我在SharedModule中有FormsModuleAngular FormsModule在不同于App Module的模块中工作不正常,angular,angular-forms,Angular,Angular Forms,我在SharedModule中有FormsModule import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { BrowserModule } from '@angular/platform-browser'; @NgModule({ declarations
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
declarations: [],
imports: [
CommonModule
],
exports : [
CommonModule,
FormsModule,
BrowserModule
]
})
export class SharedModuleModule { }
这个sharedModule被导入到每个模块中。
但是表单模块不起作用
这是错误的-
No directive found with exportAs 'ngForm'.
但当我在app.module.ts中导入此模块(其中导入了sharedModule)时,FormsModule开始工作
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LoginModule } from './login/login.module'
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
您正在导出共享模块中未导入的模块 将共享模块修改为
从'@angular/core'导入{NgModule};
从“@angular/common”导入{CommonModule};
从'@angular/forms'导入{FormsModule};
从“@angular/platform browser”导入{BrowserModule};
@NGD模块({
声明:[],
进口:[
公共模块,
FormsModule,
浏览器模块
],
出口:[
公共模块,
FormsModule,
浏览器模块
]
})
导出类SharedModuleModule{}
您正在导出尚未导入共享模块的模块
将共享模块修改为
从'@angular/core'导入{NgModule};
从“@angular/common”导入{CommonModule};
从'@angular/forms'导入{FormsModule};
从“@angular/platform browser”导入{BrowserModule};
@NGD模块({
声明:[],
进口:[
公共模块,
FormsModule,
浏览器模块
],
出口:[
公共模块,
FormsModule,
浏览器模块
]
})
导出类SharedModuleModule{}
你能把给你错误信息的模块包括进来吗?@PMO1948这是从“@angular/core”导入共享模块的模块code
import{NgModule};从“/../shared module.module”导入{SharedModuleModule};从“./loginpage/loginpage.component”导入{LoginpageComponent};从“./firstredirect/firstredirect.component”导入{FirstredirectComponent}@NgModule({declarations:[LoginpageComponent,FirstredirectComponent],imports:[SharedModuleModule]})导出类LoginModule{}能否请您包含给出错误消息的模块?@PMO1948这是从“@angular/core”导入共享模块的模块;从“/../shared module.module”导入{SharedModuleModule};从“./loginpage/loginpage.component”导入{LoginpageComponent};从“./firstredirect/firstredirect.component”导入{FirstredirectComponent}@NgModule({声明:[LoginpageComponent,FirstredirectComponent],导入:[SharedModuleModule]})导出类LoginModule{}我尝试了这种方法,但仍然遇到相同的错误。我主要关心的是,是否必须在根模块(app.module.ts)中导入功能模块?即使没有直接使用选择器或组件,我也尝试了这种方法,但仍然会遇到相同的错误。我主要关心的是,是否必须在根模块(app.module.ts)中导入功能模块?即使没有直接使用选择器或组件