import {Component} from "angular2/core";
import {CORE_DIRECTIVES, FORM_DIRECTIVES, FormBuilder, ControlGroup, AbstractControl, Validators, Control} from "angular2/common";
@Component({
selector: 'parameters-form',
directives: [FORM_DIRECTIVES,CORE_DIRECTIVES],
template: `
<h1>Parameters Form</h1>
<p [(ngModel)]='arr'>{{ arr }}</p>
<form [ngFormModel]="myForm" (ngSubmit)="onSubmit(myForm.value)" class="ui form">
<div class="field">
<label for="systemParameters">System Parameters</label>
<input type="number"
id="systemParameters"
placeholder="systemParameters Param"
[ngFormControl]="systemParameters">
<button type="button" (click)="addToArray(systemParameters.value)">Add</button>
</div>
<button type="submit" class="ui button">Submit</button>
</form>
`
})
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);
(<Control>this.systemParameters).updateValue("");
}
onSubmit(form: any): void {
console.log(this.arr);
form.systemParameters = this.arr;
console.log("your submitted value:", form)
}
}
i am trying to show the values inside Arr (array) in real-time, when user inputs value in systemParameters field by invoking the Add function which pushes the value to arr
array.
this is the error No value accessor for ''" in [arr in ParametersForm@2:9]
its cause from the ngModel
thats as much as i know.
Updated: based on Günter's comments I removed both ngModel
and Core directives. The {{arr}}
contents do not show but internally in the class they do.