在ngModel angular 2中处理变量

时间:2017-05-10 17:01:10

标签: angular

我尝试在[(ngModel)]中传递params变量item.audutModel并通过(ngModelChange)=“AddAdults(item.audutModel)”捕获[(ngModel)]的值,但是在(ngModelChange)=“AddAdults(item。 audutModel)“它理解item.audutModel是名称Model not params。对不起我的英语不好。如果您无法理解,请在评论中提问。

我的代码: html文件

         <tr *ngFor="let item of Room">
                            <td>{{item.RoomNumber}}</td>
                            <td>
                                <ion-item>
                                    <ion-label class="font-w">Số người lớn</ion-label>

                                    <ion-select [ngModel]="item.audutModel" (ngModelChange)="AddAdults(item.audutModel)">
                                        <ion-option value="1">1 người</ion-option>
                                        <ion-option value="2">2 người</ion-option>
                                        <ion-option value="3">3 người</ion-option>
                                    </ion-select>
                                </ion-item>

                            </td>
                            <td>
                                <ion-item>
                                    <ion-label class="font-w">Số trẻ em</ion-label>
                                    <ion-select [(ngModel)]=item.childModel (ngModelChange)="AddChild(item.childModel)">
                                        <ion-option value="1">1 trẻ em</ion-option>
                                        <ion-option value="2" *ngIf="  this.Adults == 1 || this.Adults == 2 ">2 trẻ em</ion-option>
                                        <ion-option value="3" *ngIf="  this.Adults == 1 ">3 trẻ em</ion-option>
                                    </ion-select>
                                </ion-item>
                            </td>
                            <td>{{this.price}}</td>
                        </tr>
                    </table>
                </ion-row>
                <ion-row>
                    <button ion-button class="add-room" (click)="AddRoom()">Add Room</button>
                    <button ion-button class="delete-room">Delete Room</button>
                </ion-row>

ts文件

     AddAdults(Adults){
    this.Adults = Adults;

    this.pricePerAd = 200;
    this.price = 1000 + Adults*this.pricePerAd;
  }
  AddChild(child){
  this.pricePerCh = 100;
  this.price += child*this.pricePerCh;
  }
  AddRoom(){
    this.audutModel = "audut";
    this.childModel = "child";
    this.RoomNumber = this.RoomNumber + 1 ;
    this.audutModel =   this.audutModel + this.RoomNumber;
    this.childModel = this.childModel + this.RoomNumber;
    this.object.audut = this.audutModel;
    this.object.child = this.childModel;

    this.Room.push( this.object);

}

1 个答案:

答案 0 :(得分:0)

您可以将$ event传递给方法。

<ion-select [ngModel]="item.audutModel" (ngModelChange)="AddAdults($event)">