以下是我选择不同产品和下拉列表的导航栏。我尝试使用[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();
}