I want to use angular material in my project.
I've added @import '~@angular/material/prebuilt-themes/pink-bluegrey.css';
into my style.css file and it works fine - tables, cards, toolbars are styled properly, but forms are not.
I've used code from example here, just by copy and paste, and the outcome looks like this:
What am I doing wrong? Here is my module (it is not main module):
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {HttpClientModule} from '@angular/common/http';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {ImageListComponent} from './image-list.component';
import {ImageListService} from './image-list.service';
import {FileSizePipe} from '../shared/file-size.pipe';
import {
MdAutocompleteModule,
MdButtonModule,
MdCardModule,
MdChipsModule,
MdTableModule
} from '@angular/material';
import {CdkTableModule} from '@angular/cdk/table';
import {EnvironmentVariableComponent, ImageRunComponent} from './image-run.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import { InputTestComponent } from './input-test.component';
@NgModule({
imports: [
CommonModule,
HttpClientModule,
BrowserAnimationsModule,
MdButtonModule,
MdCardModule,
MdChipsModule,
MdTableModule,
CdkTableModule,
MdAutocompleteModule,
FormsModule,
ReactiveFormsModule,
],
declarations: [ImageListComponent, FileSizePipe, ImageRunComponent, EnvironmentVariableComponent, InputTestComponent],
providers: [ImageListService],
exports: [ImageListComponent, ImageRunComponent, InputTestComponent]
})
export class ImageModule {
}
Here is my main module:
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppComponent} from './app.component';
import {ImageModule} from './image/image.module';
import {MdToolbarModule} from "@angular/material";
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ImageModule,
BrowserAnimationsModule,
MdToolbarModule,
FormsModule,
ReactiveFormsModule
],
bootstrap: [AppComponent]
})
export class AppModule {
}
I don't understand what am I doing wrong. My forms are not looking and behaving as it supposed.
You need to import input and form-field modules in your module imports:
import {
MdInputModule,
MdFormFieldModule
} from '@angular/material';
// ....
imports: [
MdInputModule,
MdFormFieldModule,
],
This can also happen because you didn't wrap your <input matInput>
with a <mat-form-field>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With