2017-05-24 93 views
0

我有一張代表用戶的表。我希望允許管理員通過點擊具有新用戶角色的組合框旁邊的按鈕來更改用戶角色。如果選擇的選項等於某些東西,則禁用按鈕

我試圖用manys的方式,但在我的html代碼中缺少某些東西,要連接一個選擇組合框的值的按鈕。 你能幫我嗎?瞭解如何完全綁定工作,我有一個小問題。

this.keys = Object.keys(this.roles).filter(Number)

<tr *ngFor="let oper of operaotrs"> 
      <td> {{oper.id }}</td> 
      <td> {{oper.login }} </td> 
      <td> {{oper.role}} </td> 
      <td> <div> 
      <md-select placeholder="New Role"> 
       <md-option *ngFor="let key of keys" [value]="key"> {{roles[key]}}</md-option> 
      </md-select> 
      <button md-raised-button [disabled]= "isDisabled(SOMETHING)" > PROCEED </button> 
      </div> 
      </td> 
      <td> <button> DELETE </button> </td> 
     </tr> 

回答

1

你忘了把[(ngModel)]在MD-選擇。

一旦你做到了,用[disabled]="yourNgModel === 'the value you want'"

編輯你必須要根據您的ngFor你ngModel像這樣

<tr *ngFor="let oper of operaotrs; let i = index"> 
      <td> {{oper.id }}</td> 
      <td> {{oper.login }} </td> 
      <td> {{oper.role}} </td> 
      <td> <div> 
      <md-select placeholder="New Role" [(ngModel)]="operators[i].yourPropertyYouWantToBind"> 
       <md-option *ngFor="let key of keys" [value]="key"> {{roles[key]}}</md-option> 
      </md-select> 
      <button md-raised-button [disabled]= "isDisabled(SOMETHING)" > PROCEED </button> 
      </div> 
      </td> 
      <td> <button> DELETE </button> </td> 
     </tr> 
+0

我與NgModel努力,但一旦加入,其更改所有操作員的值,而不僅僅是一個。 – VANILKA

+0

是的,請參閱我的編輯知道爲什麼 – trichetriche

+0

錯誤TypeError:無法讀取屬性'0'在Object.View_ManageUsersComponent_1.currVal_0未定義 [as - > in ngModel – VANILKA

相關問題