2016-09-14 76 views
0

我有* ngFor製作的餐館列表。我可以點擊一個我想要改變的標籤文本,使其成爲輸入字段。Typescript:從輸入更新值

我想要做的是獲取輸入字段的文本值,並在點擊按鈕時更新標籤值。

你會明白的代碼更好:

<div class="row" *ngFor="let restaurant of event.restaurants; let index = index"> 
      <div class="col-xs-5" (click)="update=true" off-click="update=false"> 
       <input *ngIf="update" type="text" name="champ" value="{{restaurant.name}}" placeholder="{{restaurant.name}}"/> 
       <a *ngIf="!update">{{restaurant.name}}</a> 
      </div> 
      <div class="col-xs-5"> 
       {{restaurant.category.description}} 
      </div> 
      <div class="col-xs-2"> 
       <button class="btn btn-default" *ngIf="!update" (click)="DelRestaurant(index)">{{'EVENT_RESTAURANT_REMOVE' | translate}}</button> 
       <button class="btn btn-default" *ngIf="update" (click)="UpdateRestaurant(index)">Modifier</button> 
      </div> 
</div> 

隨着UpdateRestaurant(index),我想要得到的輸入值,改變{{restaurant.name}}

如果你能幫助我,這將是真棒:)

回答

0

With UpdateRestaurant(index),我想要得到輸入值並更改 {{restaurant.name}}

我不是100%肯定與Angular2,但與Angular重複條目,你可以通過與該部分相關聯的對象。

這意味着你可以通過餐廳的對象..

(click)="UpdateRestaurant(restaurant)" 

與對象上改變「名稱」將更改視圖加載的對象。