angularjs - Angular 2 AbstractControl runtime -
i following answer https://stackoverflow.com/a/38064881/3874858 implement "add more" ability angular 2 application. project, associated answer uploaded on http://plnkr.co/edit/nhsisciszntqzqjxkxsk?p=preview. unfortunately, start project, have comment these lines
this.form.controls.payoffs.push(this.createpayoffformgroup(po)) this.form.controls.payoffs.push(this.createpayoffformgroup(emptypayoff)); console.log("added new pay off", this.form.controls.payoffs) this.form.controls.payoffs.removeat(index);
and type "npm start" , uncomment. if not comment them, these errors:
app/components/companyinsertion.component.ts(37,28): error ts2339: property 'payoffs' not exist on type '{ [key: string]: abstractcontrol; }'. app/components/companyinsertion.component.ts(56,24): error ts2339: property 'payoffs' not exist on type '{ [key: string]: abstractcontrol; }'. app/components/companyinsertion.component.ts(57,57): error ts2339: property 'payoffs' not exist on type '{ [key: string]: abstractcontrol; }'. app/components/companyinsertion.component.ts(63,24): error ts2339: property 'payoffs' not exist on type '{ [key: string]: abstractcontrol; }'.
so, understand, code works on runtime. tried solution, didn't seemed help: issue typescript compilation in angular2 forms changing
this.form.controls.payoffs.push(this.createpayoffformgroup(po))
to
this.form.controls['payoffs'].value.push(this.createpayoffformgroup(po))
so can run app, extremely dislike necessity comment each time start server. there solutions?
it sucks way i've found around these typescript errors cast formarray
first. it's annoying, i'm hoping typings update angular 2 in future might resolve.
(<formarray> this.form.find('pay_offs')).push(this.createpayoffformgroup(po))
Comments
Post a Comment