角度2通过单击按钮更改颜色行

时间:2017-09-11 16:05:45

标签: angular typescript

我是Angular的新人。

有一个组件:

export class ManageClientsComponent implements OnInit {

  users : CUser[] = [];
  constructor(private httpService: HttpService) {
  }
   selectedSert : CUser;
   selectedSert:CUser[] = [];
  // @Input() cUser = CUser;
  // private cUser: any;
  public ngOnInit() {
    this.initialiseData();
  }

  private initialiseData() {

    this.httpService.getData().subscribe((data: Response) => this.users = data.json());
  }

  public sellSert (sert) {

    this.selectedSert = sert;
  }

和html:

  <tbody>
  <tr  *ngFor="let sert of users let ind = index">
    <td>{{sert.Id }}</td>
    <td>{{sert.buyDate}}</td>
    <td>
      <div ngbDropdown class="d-inline-block">
        <button class="btn btn-outline-primary" id="dropdownBasic2" ngbDropdownToggle></button>
        <div ngbDropdownMenu aria-labelledby="dropdownBasic1">
          <button class="dropdown-item">Сертификат</button>
          <button class="dropdown-item">Абонент</button>
        </div>
      </div>
    </td>
    <td>{{sert.summSert}}</td>
    <td>{{sert.endSert}}</td>
    <td>
      <div ngbDropdown class="d-inline-block">
        <button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Действия</button>
        <div ngbDropdownMenu aria-labelledby="dropdownBasic1">
          <button class="dropdown-item" (click)="sellabonement(sert)">Change</button>
          <button class="dropdown-item" (click)="sellSert(sert)" [class.selected]= "sert == selectedSert">SellAll</button>
       </div>
      </div>
    </td>
  </tr>
  </tbody>

我想单击按钮SellAll并且行必须更改颜色,但是当我按下下一行按钮时,前一个颜色与它的颜色相同,但我不需要更改颜色。

0 个答案:

没有答案