I have create dynamic checkboxes using this tutorial dynamic checkbox list, now I need to implement dynamic checkbox using an API request, here what I had done,
inquiry-response.ts
interface Item {
offenceType4: string;
permSpeed: string;
actSpeed: string;
itemAttributes: ItemAttributes;
offenceLoc: string;
itemNo: string;
summonDate: string;
distCode: string;
summonType: string;
hbtlOffndr: string;
itemAmount: number;
itemAttributesCount: number;
summonAmt: string;
offenceType1: string;
offenceCode1: string;
offenceType2: string;
offenceCode2: string;
offenceType3: string;
category: string;
offenceCode3: string;
offenceCode4: string;
respCode: string;
}
interface ItemAttributes {
attribute5: string;
attribute4: string;
attribute7: string;
attribute6: string;
attribute1: string;
attribute3: string;
attribute2: string;
}
interface RootObject {
items: Item[];
status: Status;
additionalProperties: AdditionalProperties;
metadata: Metadata;
}
export class InquiryResponseMultiselectComponent implements OnInit {
form: FormGroup;
summons = [];
data: any[];
constructor(
private formBuilder: FormBuilder,
private modalService: ModalService,
private inquiryService: InquiryService
) {
this.form = this.formBuilder.group({
summons: new FormArray([], minSelectedCheckboxes(1)),
});
of(this.getSummon()).subscribe(summons => {
this.summons = summons;
this.addCheckboxes();
});
}
ngOnInit() {
this.getSummon();
}
getSummon() {
this.inquiryService.getData().pipe(map((item: RootObject) => item.items))
.subscribe(item => {
this.data = item;
});
}
private addCheckboxes() {
this.summons.map(i => {
const control = new FormControl();
(this.form.controls.summons as FormArray).push(control);
});
}
I got error state that Type 'void' is not assignable to type 'any[]'
when I want to stimulate an async request by using the RxJS operator of()
. also got problem when on the private addCheckboxes()
. need advise and help how to solve the problems.
Aucun commentaire:
Enregistrer un commentaire