typescript - Angular 4: Property "push" and "controls" does not exist on type "AbstractControl" -


i implemented code link http://plnkr.co/edit/yv94zjypwbghalb0rlk2?p=preview getting push , controls error.

here did , don't know wrong it.

import { component } '@angular/core'; import { viewcontroller,platform } 'ionic-angular'; import { formbuilder,formgroup,validators,formcontrol,formarray } '@angular/forms';  @component({   selector: 'filter-vendor',   templateurl: 'filter-vendor.html' })  export class filtervendorpage {       questions = [{id:1,text:'question 1', answers:[{id:1},{id:2}]},{id:2,text:'question 2', answers:[{id:11},{id:22}]}]   surveyform:formgroup;      constructor(     private viewctrl: viewcontroller,      private formbuilder:formbuilder      ){         this.surveyform=this.formbuilder.group({         question:formbuilder.array([])       })        for(var i=0;i<this.questions.length;i++){           let question=formbuilder.group({             question_id:[this.questions[i].id,validators.required],             answer_id:formbuilder.array([])           });           this.surveyform.controls['questions'].push(question);       } }      onchange(id, ischecked, index) {      const answers = <formarray>this.surveyform.controls.questions.controls[index].controls.answer_ids      if(ischecked) {           answers.push(new formcontrol(id))         } else {           let idx = answers.controls.findindex(x => x.value == id)           answers.removeat(idx)     }   }  } 

please me resolve issue.lot's of

typescript complains on type checking. need cast control formarray. change

1)

this.surveyform.controls['questions'].push(question); 

to

(<formarray>this.surveyform.controls['questions']).push(question); 

or

(this.surveyform.controls['questions'] formarray).push(question); 

or

(this.surveyform.get('questions') formarray).push(question); 

2)

const answers = <formarray>this.surveyform.controls.questions.controls[index].controls.answer_ids 

to

const answers = this.surveyform.get(['questions', index, 'answer_ids']) formarray; 

or

const answers = this.surveyform.get(`questions.${index}.answer_ids`) formarray; 

forked plunker


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -