Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular ';垫形式字段';不是已知元素-角度4&;角材料2_Angular_Typescript_Module_Angular Material2 - Fatal编程技术网

Angular ';垫形式字段';不是已知元素-角度4&;角材料2

Angular ';垫形式字段';不是已知元素-角度4&;角材料2,angular,typescript,module,angular-material2,Angular,Typescript,Module,Angular Material2,在我的angular应用程序中,我有一个容纳所有组件的presentation.module。我已经创建了一个共享材质。模块包含整个应用程序中使用的所有角度材质2模块。我在前面的演示文稿.module中导入了它。在我的app.module中,我导入了演示文稿.module app.module在其声明中包含app.component、header.component和footer.component 这是我的应用程序模块: @NgModule({ declarations: [ Ap

在我的angular应用程序中,我有一个容纳所有组件的
presentation.module
。我已经创建了一个
共享材质。模块
包含整个应用程序中使用的所有角度材质2模块。我在前面的
演示文稿.module
中导入了它。在我的
app.module
中,我导入了
演示文稿.module

app.module
在其声明中包含
app.component
header.component
footer.component

这是我的
应用程序模块

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    FooterComponent
  ],
  imports: [
    // Layer's modules
    PresentationModule,
    BusinessDelegateModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
const modules = [
  SharedMaterialModule,
  SharedModule,
  HomePresentationModule,
  SecurityPresentationModule,
]

@NgModule({
  imports: [...modules],
  exports: [...modules]
})
export class PresentationModule {
}
这是我的演示文稿。模块:

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    FooterComponent
  ],
  imports: [
    // Layer's modules
    PresentationModule,
    BusinessDelegateModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
const modules = [
  SharedMaterialModule,
  SharedModule,
  HomePresentationModule,
  SecurityPresentationModule,
]

@NgModule({
  imports: [...modules],
  exports: [...modules]
})
export class PresentationModule {
}
共享材料的源代码。模块

// updated: Before, i have just imported these modules without re-exporting them.
const materialModules = [
  MatButtonModule,
  MatMenuModule,
  MatToolbarModule,
  MatIconModule,
  MatCardModule,
  MatSidenavModule,
  MatFormFieldModule,
  MatInputModule,
  MatTooltipModule
];
@NgModule({
  imports: [...materialModules],
  exports: [...materialModules],
  declarations: []
})
export class SharedMaterialModule {
}
正如您在下面看到的,我已经注册了一个
安全演示。模块
,下面是它的源代码:

@NgModule({
  imports: [
    SharedModule,
    SecurityRoutingModule
  ],
  declarations: [
    LoginComponent,
    RegisterComponent,
    EmailConfirmationComponent,
    PasswordResetComponent
  ]
})
export class SecurityPresentationModule {
}
我的问题是,当我尝试在
登录.component
(在
安全演示文稿.module
中)中使用
mat输入字段时,出现以下错误:

Uncaught Error: Template parse errors:
'mat-form-field' is not a known element
但在
app.component
header.component
footer.component
中,其他角度材质2组件工作正常:

app.component.html

<div>

  <app-header></app-header>

  <div class="main-container">
    <router-outlet></router-outlet>
  </div>

  <app-footer></app-footer>

</div>

我应该在每个演示模块中导入
共享材料.module
,还是有办法解决这个问题


提前感谢。

因为您的共享模块应首先导入材料模块:

const materialModules=[
MatButtonModule,
MatMenuModule,
Mattoolbar模块,
Maticon模块,
MatCardModule,
Matside导航模块,
MatFormFieldModule,
MatInputModule,
MatTooltipModule
];
@NGD模块({
进口:[…材料模块],
出口:[…材料模块],
声明:[]
})
导出类SharedMaterialModule{
}

我收到了相同的错误,我已经添加了此
导入
属性。很抱歉,您的代码中没有此属性。你把它也放在你的演示模块里了吗?如果是这样的话,如果你能把它添加到你的帖子中,那就太好了,因为正如你所看到的,它确实会让人困惑。我已经更新了我的帖子。我不明白为什么有些材质模块在
app.component
header.component
footer.component
中运行良好,即使我在共享模块中导入了它们,也无法在其他视图中运行。哼哼,等等:您当前的角度材质版本是什么?mat表单字段是最新的,可能您不是最新的?尝试使用md表单字段查看?还有,其他组件是否也能进入演示模块,或者它们都出错了?我明白了。演示模块没有导入,这是正常的还是您忘记了?我遇到了相同的问题,尚未找到解决方案:(你能修好吗?