I am trying to style an input so that it is a certain width. I am using Angular Material 2 but for some reason the styles in the css isn't being applied to the input tag. Here is a working plunker of my issue along with the affected code:
@Component({
selector: 'my-app',
template: `
<div>
<form>
<md-input [(ngModel)]="cycleTime" type="number" name="email">
<span md-prefix>Cycle Time:</span>
<span md-suffix> minutes</span>
</md-input>
</form>
</div>
`,
styles:[`
input {
width: 50px;
text-align: right;
}
`],
directives: [MdButton, MdInput]
})
export class AppComponent {
cycleTime = 1
constructor() {}
}
How can I style the input that is being created by Angular Material 2?
You can create a typography config with the define-typography-config Sass function. Every parameter for define-typography-config is optional; the styles for a level will default to Material Design's baseline if unspecified. @use '@angular/material' as mat; $my-custom-typography-config: mat.
The matInput API page will have MAT_INPUT_VALUE_ACCESSOR, which is a token. It is mainly used to add an object into matInput where the object is of the value you want to set. Directives such as MatDatepickerInput can be used too. Here, the matInput assigns the task of choosing the value.
matInput is a directive that allows native <input> and <textarea> elements to work with <mat-form-field> . Basic Inputs.
MatFormFieldControl. An interface which allows a control to work inside of a MatFormField .
You can try to override styles of MdInput
component like this:
:host input.md-input-element {
width: 50px;
text-align: right;
}
Plunker example
Or this way:
/deep/ input {
width: 50px !important;
text-align: right;
}
:host-context .md-input-infix input {
width: 50px;
text-align: right;
}
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