我已经设置了一个表单,需要在发送要保存的任何内容之前从下拉列表中删除选定的选项,以便用户无法再次 Select 该选项.我在Stack上引用了另一个线程,但是我使用的是另一个层,所以我无法得到建议的修复程序.
我有一个formArrayName,然后是一个formGroupName,然后是一个formControlName. 每当用户单击UI上的添加首选项CTA时,formGroupName就会构建此表单
newPreference() {
this.builderPreferences.push(this.formBuilder.group({
groupId: [],
manufacturerId: [],
manufacturerDivisionId:[],
style: [''],
color: [''],
}));
}
我想做的是,当groupId与选项group.id相同时,将其从列表中删除.
[hidden]="builderPreferences.at(groupId).value==group.id?true:null"
这行代码在理想情况下应该可以工作,但它给了我一个错误消息:
"BuilderDetailComponent上不存在Property""groupId".您的意思是"group"吗?
"group"是否建议使用formBuilder.group?那么,我如何才能访问该组中的属性?
<ul formArrayName="builderPreferences">
<li *ngFor="let builderPreference of builderPreferences.controls ; let idx = index">
<div [formGroupName]="idx">
<label>Group</label>
<select formControlName="groupId" id="groupList" class="form-control mb-3" ">
<option value="0" selected>-- Select Inventory Group here --</option>
<option *ngFor="let group of groupList; index as i" value="{{ group.id }}" [hidden]="builderPreferences.at(groupId).value==group.id?true:null">
{{ group.name }}
</option>
</select>
</div>
</li>
</ul>