0

I am designing a UI section using Angular Material but my browser does not reflects the code, specifically <mat-form-field></mat-form-field>. I have tried updating my angular and npm.

I took 3 approaches to solve it but the problem persists:

1.I used the ng update in the terminal which gave me the following result: "We analyzed your package.json and everything seems to be in order. Good work!"
2.npm update which resulted in "found 0 vulnerabilities".
3. I restarted my machine.

2
  • 1
    Can you give us an stackblitz version of your code cuz we also need to check the NgModule of the app Commented Jul 13, 2022 at 1:36
  • 1
    This is the link to my project on stackblitz. add-angular-material-vqlvvs.stackblitz.io Commented Jul 14, 2022 at 9:46

1 Answer 1

1

Update: There are several issues with your code. I updated dependencies to latest versions and moved template to different for better IDE experience. It works now. Check it in StackBlitz

https://stackblitz.com/edit/add-angular-material-wbuseu


Old Response:

You need import MatFormFieldModule into your NgModule.

NgModule:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  imports: [
    BrowserModule,
    ReactiveFormsModule,
    FormsModule,
    MatFormFieldModule
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Standalone component (v14 or later):

@Component({
    selector: 'app-root',
    standalone: true,
    imports: [ MatFormFieldModule],
    template: `
        .....
    `,
})
export class AppComponent {}
Sign up to request clarification or add additional context in comments.

2 Comments

I have made the imports but still not able to see Form Fields.
There are several issues with your code. I fixed it, you can see it here. stackblitz.com/edit/add-angular-material-wbuseu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.