I know there has been similar questions about this topic but none of them worked for me since the solutions depend on either AngularJS or JQuery.
In Angular 5, I'm trying to disable the <input> of a <mat-form-field>:
test.component.html
<mat-form-field class="example-form">
<input matInput disabled [matDatepicker]="picker" [value]="startDate || ab.value" placeholder="Gültig ab" [formControl]="ab">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker disabled="false" ></mat-datepicker>
</mat-form-field>
But this doesn't work at all. I even tried to set disabled=true but this didn't get the job done. Additionally, I can't disable any of the other form fields in my component.
This is how my TypeScript file looks like:
test.component.ts
import ...
@Component({ ... })
export class TestComponent implements OnInit {
// A Couple of @Input statements
@Input() ...
// Create Formcontrollers
controlNumber = new FormControl("", [Validators.pattern("[0-9]*")]);
controlText = new FormControl("", [Validators.pattern("[A-Z-a-z]*")]);
datePicker = new FormControl(moment());
constructor(private http: HttpClient) { }
ngOnInit() {
}
...
getNotANumberMessage() {
return this.controlNumber .hasError("pattern") ? "Numbers only" : "";
}
getNotAStringMessage() {
return this.controlText.hasError("pattern") ? "Strings only" : "";
}
}
What am I missing?
Any help is highly appreciated!