You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
import { Component, OnInit } from "@angular/core";
import { FormGroup, FormControl, Validators, FormGroupDirective, NgForm } from '@angular/forms';
import { ErrorStateMatcher } from '@angular-mdc/web/form-field/typings/error-state-matcher';
export class APErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted = form && form.submitted;
return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));
}
}
@Component({
templateUrl: './my-component.html'
})
export class MyComponent implements OnInit {
matcher = new APErrorStateMatcher();
demoForm: FormGroup;
ngOnInit(): void {
this.demoForm = new FormGroup({
username: new FormControl(
{ value: null, disabled: false },
[Validators.required, Validators.minLength(3), Validators.maxLength(11)]
)
});
}
get validationMessage(): string {
if (this.demoForm.controls['username'].hasError('minlength')) {
return 'Username is not long enough';
} else if (this.demoForm.controls['username'].hasError('maxlength')) {
return 'Username is max length is 11';
} else if (this.demoForm.controls['username'].hasError('required')) {
return 'Field is required';
}
return undefined;
}
submit(f: NgForm | FormGroup) {
if (f.invalid) { return; }
}
But I had error: Can't bind to 'validationMessage' since it isn't a known property of 'mdc-text-field'
I thought that your documentation is not full and I did not imported this directive or I incorrect imported textfiled. Can you help me please?
The text was updated successfully, but these errors were encountered:
yalesnikov
changed the title
Can you help to correct import MDC modules to the project?
Can't bind to 'validationMessage' since it isn't a known property of 'mdc-text-field'
Jun 18, 2020
Hi, I tried to import TextField to my project and I had error.
I imported MdcTextFieldModule and added it to the import array into NgModule
my-module.ts
I used a validationMessage directive in html. I added this directive into mdc-text-field.
my-component.html
I used methods from example at official your site: https://trimox.github.io/angular-mdc-web/#/angular-mdc-web/text-field/examples
my-component.ts
But I had error:
Can't bind to 'validationMessage' since it isn't a known property of 'mdc-text-field'
I thought that your documentation is not full and I did not imported this directive or I incorrect imported textfiled. Can you help me please?
The text was updated successfully, but these errors were encountered: