3

I’m using Material on an Angular project.

All the Material components I use work except matInput.

I import the component well and I have the impression that it is well detected as such but its css is not taken into account.

import { MatInputModule } from '@angular/material/input';
import { NgModule } from '@angular/core';
import { MatButtonModule } from "@angular/material/button";
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';


@NgModule({
  declarations: [],
  imports: [],
  exports: [
    MatButtonModule,
    MatInputModule,
    MatFormFieldModule,
    MatSlideToggleModule
  ]
})
export class MaterialModule {
}

_

    <form fxLayout="column" fxLayoutGap="1rem">
        <input type="text" mat-input />
        <input matInput>

        <button mat-flat-button>button</button>
    </form>

enter image description here

Mat Button work but Mat Input no.

3
  • It's possible that you have a global css declaration of your own or another library such as bootstrap that is messing with the global styles definitions. Can you confirm it? Commented Apr 5, 2021 at 16:17
  • I use Theming Material > @import '~@angular/material/theming' on styles.scss Commented Apr 5, 2021 at 16:53
  • But it doesn't have to be that because even if you deactivate Theming Material, the problem remains the same. Commented Apr 5, 2021 at 16:55

1 Answer 1

0

Firstly you need to add any theme in styles.scss file. For example:

@import '~@angular/material/prebuilt-themes/indigo-pink.css';

After this you should use matInput with <mat-form-field> tag. For example:

<mat-form-field>
    <input type="text" matInput />
</mat-form-field>

Quote from documentation:

matInput is a directive that allows native and elements to work with <mat-form-field>.

Sign up to request clarification or add additional context in comments.

Comments

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.