如何从另一个检查输入自动设置检查输入的值,反之亦然?

时间:2017-07-31 17:41:23

标签: angular

以下是我选择不同产品和下拉列表的导航栏。我尝试使用[ngModel] =“brand?.selected但它不起作用或我使用不正确。我该如何处理?我需要实现OnChanges和/或DoCheck吗?如果我从sidenav选择google,如何你自动设置下拉列表的检查输入吗?

<div [ngClass]="displayBrand">                    
  <ul *ngFor="let brand of brands | orderby: ['fieldName']; let i = 
    index">
    <div class="checkbox">
      <input type="checkbox" [value]="brand.selected"
        (change)="onBrand($event, i)">{{ brand.fieldName}}
        ({{brand.getCount()}})
      <a (click)="onBrandSite(brand.fieldName)">site</a>    
    </div>
  </ul>
</div 

<div class="btn-group" role="group" *ngIf="isBrand">
  <button type="button" class="btn btn-default dropdown-toggle" data-
   toggle="dropdown" 
   aria-haspopup="true" aria-expanded="false">Brands<span 
  class="caret"></span>
  </button>
    <ul class="dropdown-menu">
      <ul *ngFor="let brand of brands | orderby: ['fieldName']; let i 
         = index">
        <li class="checkbox"><input type="checkbox" 
         [value]="brand.selected" 
         (change)="onBrand($event, i)">{{ brand.fieldName}}
         <a (click)="onBrandSite(brand.fieldName)">site</a>
        </li>
      </ul> 
    </ul>
  </div>

这是我选择品牌的代码。品牌被宣布为品牌:SearchField [] = [];

export class SearchField {
  fieldName: string;
  products: Product[];
  selected: boolean;
}

onBrand(event, index: number) {
  var isChecked = event.currentTarget.checked;
  this.brands[index].selected = isChecked;
  this.getClickedFilters();
  this.getClickedSelected();
}       

enter image description here

0 个答案:

没有答案