Reputation: 510
I'm trying to make a simple page for people to enter the form data which uses materials module in angular. When trying to display multiple mat-form-field
s, only the first one is displayed initially. Only when I click on one of the form field are the other ones displayed.
-app
|
|-contactus(folder)
|-app.component.html
|-app.component.ts
|-material.module.ts
|-app.module.ts
<div class="back">
<div class="title" style="margin: auto">
<mat-card>
<h2> CONTACT US IS UNDER CONSTRUCTION </h2>
</mat-card>
</div>
<form>
<mat-form-field>
<textarea matInput placeholder="Details"></textarea>
</mat-form-field>
<mat-form-field>
<textarea matInput placeholder="Other"></textarea>
</mat-form-field>
</form>
</div>
import { Component, OnInit, NgModule } from '@angular/core';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
@Component({
selector: 'app-contactus',
templateUrl: './contactus.component.html',
styleUrls: ['./contactus.component.css']
})
export class ContactusComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { MaterialModule } from './material.module';
import { ContactusComponent } from './contactus/contactus.component';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
declarations: [
AppComponent,
ContactusComponent
],
imports: [
BrowserModule,
MaterialModule,
AppRoutingModule,
FormsModule,
ReactiveFormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import { NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {
MatButtonModule,
MatToolbarModule,
MatCardModule,
MatButtonToggleModule,
MatInputModule
} from '@angular/material';
@NgModule({
imports: [
MatButtonModule,
MatCardModule,
MatToolbarModule,
MatButtonToggleModule,
MatInputModule
],
exports: [
MatButtonModule,
MatCardModule,
MatToolbarModule,
MatButtonToggleModule,
MatInputModule
],
})
export class MaterialModule { }
Why is it not displaying the other form-fields initially?
Upvotes: 1
Views: 545
Reputation: 526
This happened to me just now and the fix was to import BrowserAnimationsModule
into app.module.ts
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
...
@NgModule({
...
imports: [
BrowserAnimationsModule,...
]
...
Upvotes: 1