Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,17 @@ describe("DynamicFormInstanceService test suite", () => {
expect(service.getFormControlInstance(model.id, 0)).toBe(instanceRef);
});

it("should no more have this reference at the given index, when deleted", () => {
it("should still have this reference at the given index, when deleting the first one", () => {
service.setFormControlInstance(model, instanceRef, 0);
service.setFormControlInstance(model, instanceRef, 1);
service.removeFormControlInstance(model.id, 0);
expect(service.getFormControlInstance(model.id, 0)).toBeDefined();
});

it("should no more have this reference at the given index, when deleting the first one two times", () => {
service.setFormControlInstance(model, instanceRef, 0);
service.setFormControlInstance(model, instanceRef, 1);
service.removeFormControlInstance(model.id, 0);
service.removeFormControlInstance(model.id, 0);
expect(service.getFormControlInstance(model.id, 0)).toBeUndefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export class DynamicFormInstancesExplicitService implements DynamicFormInstances

const arrayRef: Array<ComponentRef<DynamicFormControl>> =
this.formControlInstances[model.id] as Array<ComponentRef<DynamicFormControl>> || [];

arrayRef[index] = instance;

/**
* Use splice to add element
*/
arrayRef.splice(index, 0, instance);
this.formControlInstances[model.id] = arrayRef;

} else {
Expand All @@ -45,7 +46,10 @@ export class DynamicFormInstancesExplicitService implements DynamicFormInstances
if (index !== undefined) {

if (Array.isArray(instanceRef) && instanceRef[index]) {
instanceRef[index] = undefined;
/**
* Use splice to remove elements
*/
instanceRef.splice(index, 1);
} else {
throw new Error(`There exists no control with id: ${modelId} and/or index ${index}`);
}
Expand Down