2017-05-24 117 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

相关问题