Friends,
I have a form with some FormGroup values . I need to take some localstorage value and process inside constructor as shown in code :
constructor(public navCtrl: NavController, public navParams: NavParams,public http: HttpClient,public formbuilder: FormBuilder,public propertyProvider: PropertyProvider, public gosearch: GoserviceProvider, private storage: Storage ) {
//checking for storage ready
this.storage.ready().then(async (lf) => {
//getting the value asyncrone, check the async in the inner function declaration
//let lbid = await lf.getItem('LBID');
this.lbid = await lf.getItem('LBID');
this.lbname = await lf.getItem('lbname');
this.tnyLBCategory = await lf.getItem('tnyLBCategory');
this.lbtype = await lf.getItem('lbtype');
this.distid = await lf.getItem('distid');
//this.lbid = 172; //-- Tested value
//this.distid = 1; //-- Tested Value
this.lbtype = 3; // for municipality -- Tested value
this.data.result = '';
if(this.lbtype == 5){
this.getZonalOffice(this.lbid,this.lbtype); // calling api zonal office ...
this.getAssessmentYear(this.lbid); // calling api ward year...
this.formgroup = formbuilder.group({
zonaloffice:['',Validators.required],
wardyear:['',Validators.required],
wardnumber: ['',Validators.required],
doornumber: ['',Validators.required],
subnumber: ['']
});
this.zonaloffice = this.formgroup.controls['zonaloffice'];
this.wardyear = this.formgroup.controls['wardyear'];
this.wardnumber = this.formgroup.controls['wardnumber'];
this.doornumber = this.formgroup.controls['doornumber'];
this.subnumber = this.formgroup.controls['subnumber'];
this.data.zonaloffice = '';
this.data.wardyear = '';
this.data.wardnumber = '';
this.data.doornumber = '';
this.data.subnumber = '';
}
if(this.lbtype == 3){ // for municipality
this.getZonalOffice(this.lbid,this.lbtype);
this.getAssessmentYear(this.lbid);
this.formgroup = formbuilder.group({
zonaloffice:['',Validators.required],
wardyear:['',Validators.required],
wardnumber: ['',Validators.required],
doornumber: ['',Validators.required],
subnumber: ['']
});
this.zonaloffice = this.formgroup.controls['zonaloffice'];
this.wardyear = this.formgroup.controls['wardyear'];
this.wardnumber = this.formgroup.controls['wardnumber'];
this.doornumber = this.formgroup.controls['doornumber'];
this.subnumber = this.formgroup.controls['subnumber'];
this.data.zonaloffice = '';
this.data.wardyear = '';
this.data.wardnumber = '';
this.data.doornumber = '';
this.data.subnumber = '';
}
if(this.lbtype == 4){
this.getZonalOffice(this.lbid,this.lbtype);
this.getAssessmentYear(this.lbid);
this.formgroup = formbuilder.group({
zonaloffice:['',Validators.required],
wardyear:['',Validators.required],
wardnumber: ['',Validators.required],
doornumber: ['',Validators.required],
subnumber: ['']
});
this.zonaloffice = this.formgroup.controls['zonaloffice'];
this.wardyear = this.formgroup.controls['wardyear'];
this.wardnumber = this.formgroup.controls['wardnumber'];
this.doornumber = this.formgroup.controls['doornumber'];
this.subnumber = this.formgroup.controls['subnumber'];
this.data.zonaloffice = '';
this.data.wardyear = '0';
this.data.wardnumber = '';
this.data.doornumber = '';
this.data.subnumber = '';
}
});
}
but i got errors as
- ERROR Error: formGroup expects a FormGroup instance. Please pass one in.
- ERROR CONTEXT Object { view: Object, nodeIndex: 4, nodeDef: Object, elDef: Object, elView: Object }
- ERROR TypeError: this.form is undefined
- ERROR CONTEXT Object { view: Object, nodeIndex: 33, nodeDef: Object, elDef: Object, elView: Object } PropertyTaxPage.ngfactory.js
Please any body advise how this can done for me in proper way
Thanks
Anes