0

I am able to get the values from the child but I need to validate the values in my parent component that is present or not.

parent.html :

<browser (notify)="onselect($event)"  [template]="coreActivity" (onselect)="onselect($event)" formControlName="template" ></browser>

parent.ts :

export class CreateCommunityComponent implements OnInit {  userForm: FormGroup;  public tagarray=[];   coreActivity = [
   {value: 'Professional', viewValue: 'Professional', tool: 'Forum' },
   {value: 'Travel', viewValue: 'Travel', tool: 'quora'},
   {value: 'Arts', viewValue: 'Arts', tool: 'stackoverflow'},
   {value: 'Technology', viewValue: 'Technology', tool: 'quora'},
   {value: 'Business', viewValue: 'Business', tool: 'Forum'},
   {value: 'Science', viewValue: 'Science', tool: 'quora'},
   {value: 'Education', viewValue: 'Education', tool: 'quora'}
 ];    visibility = [
     {value: 'Public', viewValue: 'Public'},
     {value: 'Private', viewValue: 'Private'},
     {value: 'Moderate', viewValue: 'Moderate'}
   ];    tags = [
     {value: 'tag-one', viewValue: 'tagone'},
     {value: 'tag-two', viewValue: 'tagtwo' },
     {value: 'tag-three', viewValue: 'tagthree'}
   ];
 constructor(private dialog: MdDialog, private fb: FormBuilder,private router: Router) {    this.createForm();    }  createForm() {
       this.userForm = this.fb.group({
         domainName: ['', [Validators.required, Validators.pattern('[a-z.]{8,20}')]],
         communityName: ['', Validators.required],
         Purpose: ['', Validators.required],
         visibility: ['Public', Validators.required],
         template: ['',Validators.required],
         tagSelection: ['', Validators.required],
         termscondition: ['', Validators.required]
       });
   }
//  check whether the card is clickable or not 
onselect(selectedTemplate: any)
{
  console.log(selectedTemplate);
  return selectedTemplate;
}

It is giving error while I am validating the child value is present or not:

ERROR Error: No value accessor for form control with name: 'template'

3
  • please provide some more html content Commented Jun 20, 2017 at 6:52
  • Have you imported FormsModule and ReactiveFormsModule? Commented Jun 20, 2017 at 6:54
  • Could you add the template for the child as well? Commented Jun 23, 2017 at 16:03

1 Answer 1

0

You need to add ngDefaultControl to your <browser> tag.

<browser ngDefaultControl (notify)="onselect($event)"  
  [template]="coreActivity" (onselect)="onselect($event)" 
formControlName="template" ></browser>

Hope this will work for you.

Sign up to request clarification or add additional context in comments.

4 Comments

i am using formgroup to validate my form fields and i need to validate the template field using formcontrol
Can you remove and try that ?
getting an error :ERROR Error: No value accessor for form control with name: 'template'
Same error you are getting when you are removing the formGorup?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.