2
export class ParametersForm {
  myForm: ControlGroup;
  systemParameters: AbstractControl;
  arr: number[];
  constructor(fb: FormBuilder) {
    this.myForm = fb.group({
      "realisations" : [""],
      "numConstSteps" : [""],
      "timeHorizon": [""],
      "continuationStep" : [""],
      "continuationStepSign" : [""],
      "numberOfModelParameters" : [""],
      "systemParameters" : [],
      "param" : [""],
      "netLogoFile" : [""],
      "numberOfModelVariables" : [""],
      "restrictOperator" : [""],
      "liftOperator" : [""],
      "xInitial" : [""]

    });
    this.arr = [];
    this.systemParameters = this.myForm.controls["systemParameters"];
  }
  addToArray(value: any): void {
    this.arr.push(value);
    this.systemParameters = null;
  }
  onSubmit(form: any): void {
    console.log(this.arr);
    form.systemParameters = this.arr;
    console.log("your submitted value:", form)
  }
}

form

@Component({
    selector: 'parameters-form',
    directives: [FORM_DIRECTIVES],
    template: `
      <h1>Parameters Form</h1>

      <form [ngFormModel]="myForm" (ngSubmit)="onSubmit(myForm.value)" class="ui form">

<div class="field">
            <label for="systemParameters">System Parameterss</label>
            <input type="number"
                   id="systemParameters"
                   placeholder="systemParameters Param"
                   [ngFormControl]="myForm.controls['systemParameters']" #systemParam>

            <button type="button" (click)="addToArray(systemParam.value)">Add</button>
          </div>

<button type="submit" class="ui button">Submit</button>
      </form>
    `
})

The problem is when i click the "add" button the field is not resetting so that i can input my next value without removing old one.

1 Answer 1

1

Instead of

this.systemParameters = null;

this should work

import { Control } from "angular2/common";

(<Control>this.systemParameters).updateValue('');
Sign up to request clarification or add additional context in comments.

2 Comments

Um thanks but this does not compile "cannot find name control"
You need to import Control I guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.