Access validation information from Angular 2 model-driven form? -


i have angular 2 form uses template-driven approach converting model-driven approach. currently, form uses style this:

.ng-valid[required] {   border-left: 5px solid #42a948; /* green */ } 

this marks of fields have required attribute green bar.

now moving model-driven, control no longer has "required" attribute. there way access validation rules associated control (see below) binding in form?

  buildform() {     this.heroform = this.fb.group({       'name': [this.model.name,                 validators.compose([validators.required,                           validators.minlength(4),                           validators.maxlength(24)])],       'alterego': [this.model.alterego],       'power': [this.model.power, validators.required]     }); 

i able provide logic using set of internal data structures , building method this:

  isrequired(controlname: string): boolean {       if (object.keys(this._validationmessages).includes(controlname)) {         return object.keys(this._validationmessages[controlname]).includes('required');}       return false;   } 

the template binds method, passing in name of control.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo