Posts

Showing posts with the label angular4-forms

Form validation Angular 4 | multi-field validation | Set error on empty Field depending on other field

Form validation Angular 4 | multi-field validation | Set error on empty Field depending on other field I have a form where two fields (' From date ' and ' To Date ') are there along with other fields. Requirement: User can provide only ' From Date ' If both date are given ' From date ' must NOT be greater than ' To Date '; if given ' To Date ' will be underlined with Red. If one provides ' To Date ' only, then the ' From Date ' will be underlined with Red. To do this I used a frombuilder 'SrchForm' like this: myForm(){ this.srchGrp = this.SrchForm.group({ //other FormcontrolNames from_date : '', // from_date controlname for 'From Date' field to_date : '', // to_date controlname for 'To Date' field }, {validator: this.fromNtoValidate('from_date', 'to_date')}) } And, fromNtoValidate(from_date, to_date){ return (group: FormGro...

Child To Parent Value access using ViewChild

Child To Parent Value access using ViewChild I have read about articles in angular6, 3 ways to communicate in child to parent.if its wrong,please demonstrate if possible 1)output emitter 2)using viewchild 3)shared Service. So here i need to understand how to communicate the viewchild from child to parent. In below demo, have created a form in child component,when child component form is valid, that should be reflected in parent component.In this demo when components gets loaded in ngafterViewInit hook the view child value , its working as expected , but when type some thing , child component form is valid,button enabled in child form ,those changes not reflected in the parent component which needs to valid , but its not working as expected. can anyone give the best approach? parent component.html <h1> Parent Component</h1> <button class="btn btn-danger " disabled="{{check}}">CheckParentEnable</button> <div class="childComponent...