0

I'm trying to bind an Array of Object with ([ngModel]) can anyone provide me an exemple to do that please ?

i have an Array of Parameters that i want to bind it to my form here is the structure :

 class Parameter {
    label: string;
    description: string;
    mandatory: string;
    parameterType: string;
    dataType: string;
    requestType: string;
    processParameterIdentifier: string;

so what i'm trying to do is to edit the values of the different object present on the array, i don't know how to do it exactly, this is the template of a single object : but how to it in the case of the array ?

<div *ngIf = "filtred" class="form-group" ngControl ="parameters" >

                    <label>Paramètres</label>

                    <div class="form-group" ngControlGroup="Parameter" 
                    *ngFor="let parametre of processListe?.Process?.parameters,
                    let i = index">

                        <h2>Param {{ i+1 }}</h2>



                        <label>label</label>
                        <input class="form-control" type="text" ngControl="label" value="{{ parametre?.Parameter?.label }}" />
                       <div class="alert alert-info">
                       <strong>Default :</strong> {{ parametre?.Parameter?.label }}.
                       </div>


                        <label>description</label>
                        <input class="form-control" type="text" ngControl="description" value="{{ parametre?.Parameter?.description }}" />
                       <div class="alert alert-info">
                       <strong>Default :</strong> {{ parametre?.Parameter?.description }}.
                       </div>

                        <label>parameterType</label>
                        <input class="form-control" type="text" ngControl="parameterType" value="{{ parametre?.Parameter?.parameterType }}" />
                       <div class="alert alert-info">
                       <strong>Default :</strong> {{ parametre?.Parameter?.parameterType }}.
                       </div>

                        <label>mandatory</label>
                        <input class="form-control" type="text" ngControl="mandatory" value="{{ parametre?.Parameter?.mandatory }}" />
                       <div class="alert alert-info">
                       <strong>Default :</strong> {{ parametre?.Parameter?.mandatory }}.
                       </div>

                        <label>dataType</label>
                        <input class="form-control" type="text" ngControl="dataType" value="{{ parametre?.Parameter?.dataType }}" />
                     <div class="alert alert-info">
                       <strong>Default :</strong> {{ parametre?.Parameter?.dataType }}.
                       </div>
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Anna
  • 1,607
  • 5
  • 13
  • 18
  • Please post some code that demonstrates what you try to accomplish. There is nothing special to that except that change detection won't detect changes inside the array. – Günter Zöchbauer Jul 25 '16 at 07:39
  • What's the problem? The code in your question doesn't contain `[(ngModel)]=".."`. – Günter Zöchbauer Jul 25 '16 at 07:48
  • the problem is i don't know how to bind an object of the array, this is a simple observerable case i'm printing the values on inputs so i can show you the structure , i haven't found an example of ngModel Array case – Anna Jul 25 '16 at 07:54
  • I don't even know where you want to bind what for what purpose. If you want to bind using `[(ngModel)]=".."` I would assume to find this somewhere in your code. I suggest you start at http://angular.io, there are lots of great tutorials. – Günter Zöchbauer Jul 25 '16 at 07:58
  • i'm trying to bind an Array of object that i'm getting from my server to my form, when getting the objects, i need to let the user change the values of this array object one by one in my form so when getting these values i'm saving it on a certain array, i just want a hint to bind it to my form and with the ngModel i didn't found an example case of Array bind i'm looking for a plnkr or anything useful like array binding, i'm sorry if i'm not clear enough ... – Anna Jul 25 '16 at 08:04

0 Answers0