Skip to content

Commit

Permalink
path getter added for DynamicFormArrayGroupModel (closes #414)
Browse files Browse the repository at this point in the history
  • Loading branch information
udos86 committed Jul 7, 2017
1 parent 63ac803 commit 37fa5a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/app/basic/basic-example.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const BASIC_EXAMPLE_ARRAY_MODEL = [
id: "basicFormArray",
initialCount: 2,
label: "Example Array Model",
createGroup: () => {
groupFactory: () => {
return [
new DynamicCheckboxModel({

Expand Down
2 changes: 1 addition & 1 deletion example/app/bootstrap/bootstrap-example.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export const BOOTSTRAP_EXAMPLE_MODEL = [
id: "bootstrapFormArray",
initialCount: 5,
label: "Example Array Model",
createGroup: () => {
groupFactory: () => {
return [
new DynamicInputModel(
{
Expand Down
2 changes: 1 addition & 1 deletion example/app/foundation/foundation-example.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export const FOUNDATION_EXAMPLE_MODEL = [
id: "foundationFormArray",
initialCount: 5,
label: "Example Array Model",
createGroup: () => {
groupFactory: () => {
return [
new DynamicInputModel(
{
Expand Down
17 changes: 16 additions & 1 deletion modules/core/src/model/form-array/dynamic-form-array.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class DynamicFormArrayGroupModel {

private _parent: DynamicFormArrayGroupModel | null = null;

constructor(context: DynamicFormArrayModel, group: DynamicFormControlModel[] = [], index: number | null = null) {
constructor(context: DynamicFormArrayModel, group: DynamicFormControlModel[] = [], index: number = null) {

this.context = context;
this.group = group;
Expand All @@ -30,6 +30,21 @@ export class DynamicFormArrayGroupModel {
this._parent = parent;
}

get path(): string[] {

let path: string[] = [],
groupModel: DynamicFormArrayGroupModel = this;

while (groupModel) {

path.unshift(groupModel.context.id, groupModel.index.toString());

groupModel = groupModel.parent;
}

return path;
}

get(index: number): DynamicFormControlModel {
return this.group[index];
}
Expand Down

0 comments on commit 37fa5a9

Please sign in to comment.