我对SharedModule的工作方式有疑问。我需要在模块上使用FormGroups和FormControl,因此必须将SharedModule导入到该模块。 SharedModule导出FormsModule,ReactiveFormsModule,所以我不知道为什么它还不能识别Formgroup和FormControl名称。这是我得到的错误:无法绑定到“ formGroup”,因为它不是“ form”的已知属性。
这是我的shared.module.ts:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RequiredLabelDirective } from './directives/required-label.directive';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
CommonModule,
ReactiveFormsModule,
],
declarations: [RequiredLabelDirective],
exports: [
RequiredLabelDirective,
FormsModule,
ReactiveFormsModule
]
})
export class SharedModule { }
这是我要导出SharedModule的模块,以便:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule} from '../../shared/shared.module';
@NgModule({
imports: [
CommonModule,
SharedModule
],
declarations: []
})
export class MisDatosModule { }
这是MisDatos.component.ts的代码:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-mis-datos',
templateUrl: './mis-datos.component.html',
styleUrls: ['./mis-datos.component.scss']
})
export class MisDatosComponent implements OnInit {
profileForm = new FormGroup({
Name: new FormControl('NombreDelProfesional'),
Surname: new FormControl('ApellidoDelProfesional'),
Dni: new FormControl('DNIPROFESIONAL'),
Email: new FormControl('unEmail@gmail.com'),
Password: new FormControl('ayquepasswordmasmalo'),
Phone: new FormControl('12354566')
});
constructor() { }
ngOnInit() {
}
}
这是我的Angular Project的结构。
我还有其他问题。例如,如果MisDatos没有模块,将会发生什么?我可以在ProfesionalModule上导入SharedModule,这可以工作吗?我的意思是,您可以使用另一个组件中没有他一个模块的模块吗?
希望您能帮助我,非常感谢。我是初学者。
答案 0 :(得分:0)
SharedModule
也应导入FormsModule
。您不能导出尚未在Angular模块中导入或声明的内容。