Angular材料形式字段无效

发布于 2025-02-12 15:20:20 字数 1841 浏览 0 评论 0原文

我正在关注此 https://material.angular.io/compar.io/components/form-firfield/概述 但是在我的代码表格字段中行为没有更改,也没有出现标签 例如,如果外观填充,看起来像默认表单

 <mat-form-field  appearance="fill">
       <mat-label>First Name</mat-label>
       <input placeholder="FirstName<" formControlName="FName">
 </mat-form-field>

屏幕 [1]: https://i.sstatic.net/6ihkn.png 但是,即使我更改外观=“标准”或外观=“轮廓”它不会改变行为 app-module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { MessageFormComponent } from './message-form/message-form.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MatFormFieldModule, MAT_FORM_FIELD_DEFAULT_OPTIONS} from '@angular/material/form-field';
import {MatButtonModule} from '@angular/material/button';
import {FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from  '@angular/common/http';
import {MatInputModule} from '@angular/material/input'

@NgModule({
  declarations: [
    AppComponent,
    MessageFormComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    FormsModule,
    ReactiveFormsModule,
    MatFormFieldModule,
    MatButtonModule,
    MatInputModule,
    HttpClientModule

  ],
  providers: [{provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {appearance: 'fill'}}],
  bootstrap: [AppComponent]
})
export class AppModule { }

有人可以告诉需要做什么

I am following this https://material.angular.io/components/form-field/overview
but in my code form fields behaviour isn't changing also label isn't appearing
for example if the appearance is fill it look like as default form

 <mat-form-field  appearance="fill">
       <mat-label>First Name</mat-label>
       <input placeholder="FirstName<" formControlName="FName">
 </mat-form-field>

Screen
[1]: https://i.sstatic.net/6ihkn.png
but even I change the appearance="standard" or appearance="outline" it doesn't change the behaviour
App-module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { MessageFormComponent } from './message-form/message-form.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MatFormFieldModule, MAT_FORM_FIELD_DEFAULT_OPTIONS} from '@angular/material/form-field';
import {MatButtonModule} from '@angular/material/button';
import {FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from  '@angular/common/http';
import {MatInputModule} from '@angular/material/input'

@NgModule({
  declarations: [
    AppComponent,
    MessageFormComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    FormsModule,
    ReactiveFormsModule,
    MatFormFieldModule,
    MatButtonModule,
    MatInputModule,
    HttpClientModule

  ],
  providers: [{provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {appearance: 'fill'}}],
  bootstrap: [AppComponent]
})
export class AppModule { }

can someone tell what needs to be done

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹤仙姿 2025-02-19 15:20:20

你们都很好。只是缺少matinput您的&lt; Input&gt;上的指令

 <mat-form-field  appearance="fill">
       <mat-label>First Name</mat-label>
       <input placeholder="FirstName" matInput> formControlName="FName">
 </mat-form-field>

You are all good. just missing matInput directive on your <input>

 <mat-form-field  appearance="fill">
       <mat-label>First Name</mat-label>
       <input placeholder="FirstName" matInput> formControlName="FName">
 </mat-form-field>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文