javascript - 使用角度模糊时的新数组
问题描述
我正在使用选择。他看到 select 中选择的内容做了一个 get 并检查以根据 select 带来值。问题是在模糊底部类别时使用 this.categoryList = [] 会清除顶部类别,如果我不使用它,它将在数组中增加。我希望在单击选择时根据获取显示选项。
COMPONENT TS
//categoryInit() in ngOnit//
categoryInit() {
this.initcategory((<HTMLInputElement>document.getElementById("category")).value)
}
getcategory(index?:any) {
const value = (<FormArray>this.feedstockForm.value.feedstock[index].category);
console.log(this.categoryList)
this.initcategory(value)
}
initcategory(value) {
console.log(value)
const totalResults = 0;
const searchModel = {
text: '',
status: '',
};
this.feedstockService.getFeedstock(totalResults, searchModel)
.subscribe(response => {
const feedstocks = response.results.filter(x => x.category === value)
feedstocks.forEach(feedstock => this.categoryList.push(feedstock.name))
})
}
<ng-container [formGroup]="feedstockForm">
<ng-container formArrayName="feedstock">
<accordion [closeOthers]="oneAtATime" *ngFor="let fcFeedStock of feedstockForm.get('feedstock')?.controls; let i = index">
<accordion-group heading="{{ fcFeedStock.get('position').value }} / {{ fcFeedStock.get('category').value }}" [formGroupName]="i">
<div>
<i class="material-icons close-category" (click)="removeFeedstockCategory(i)">
close
</i>
</div>
<div class="divide-section">
<div class="first-column">
<div class="header-section options">
<span>ADICIONAR COMPONENTE</span>
<i class="material-icons" (click)="addFeedstockComponent(i)">
add
</i>
</div>
<div class="form-group">
<label for="category">CATEGORIA</label>
<select class="form-control" id="category" (change)=getcategory(i) formControlName="category">
<option value="" selected ></option>
<option *ngFor="let cat of categories" [value]="cat.value">
{{cat.viewValue}}
</option>
</select>
解决方案
推荐阅读
- r - 如何从一个数据框中的模式中获取另一个数据框?
- python - 具有第 i 个元素的 Torch 张量作为所有先前的乘积
- amazon-web-services - Terraform 嵌套 for_each aws_acm_certificate domain_validation_options
- python - 从复杂的多段落文档中提取单词并将其输出为多行逗号分隔文件
- r - 错误:无法加载外部实体“http://.......”
- swift - SwiftUI:拖入空列表时崩溃
- amazon-web-services - aws ec2 describe-instances 返回空数组
- angularjs - 如何避免在angularJs中从一个选项卡导航到另一个选项卡时多次触发$on?
- tensorflow - 与 model.predict 相比,Keras model.fit 非常非常慢
- google-analytics - 在 nuxt.js 中设置 Google Analytics 4