Angular 角度材质2-如何更改垫形式字段和垫形式自定义CSS

Angular 角度材质2-如何更改垫形式字段和垫形式自定义CSS,angular,angular-material2,Angular,Angular Material2,我想要mat表单字段/mat输入自定义CSS 示例1)角材料2 结果:view.html 违约: 我想要伊洛德: 使用ng invalid和ng invalid类,如下所示: input.ng-valid { border: 2px solid green; } input.ng-invalid { border: 2px solid red; } 只有在使用FormGroup时,Angular才会动态地为您添加这些额外的类 //*.component.ts construct

我想要mat表单字段/mat输入自定义CSS

示例1)角材料2

结果:view.html 违约: 我想要伊洛德:


使用
ng invalid
ng invalid
类,如下所示:

input.ng-valid {
    border: 2px solid green;
}
input.ng-invalid {
    border: 2px solid red;
}
只有在使用FormGroup时,Angular才会动态地为您添加这些额外的类

//*.component.ts
constructor() {
    this.affiliateForm = new FormGroup({
        affiliateName: new FormControl('', Validators.required)
    })
}
例如:

<!-- *.component.html -->
<form [formGroup]="affiliateForm">
    <mat-form-field >
        <input matInput
               formControlName="affiliateName"
               placeholder="test">
    </mat-form-field>
</form>

使用css更改材料输入的样式=>stackoverflow.com/a/54409733/2736742
input.ng-valid {
    border: 2px solid green;
}
input.ng-invalid {
    border: 2px solid red;
}
//*.component.ts
constructor() {
    this.affiliateForm = new FormGroup({
        affiliateName: new FormControl('', Validators.required)
    })
}
<!-- *.component.html -->
<form [formGroup]="affiliateForm">
    <mat-form-field >
        <input matInput
               formControlName="affiliateName"
               placeholder="test">
    </mat-form-field>
</form>