我的问题很简单:我有一个像这样的复选框列表:
<div class="form-group">
<label for="options">Options :</label>
<label *ngFor="#option of options" class="form-control">
<input type="checkbox" name="options" value="option" /> {{option}}
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
我想发送一系列选定的选项,例如:
[option1, option5, option8]如果选择了选项1,5和8.此数组是我想通过HTTP PUT请求发送的JSON的一部分.
谢谢你的帮助!
我想从我的复选框中获取值,但我只能得到真或假.
这是我的模板:
<h4>Categories</h4>
<div class="form-check" *ngFor="let cat of categories$|async">
<input class="form-check-input" [(ngModel)]="cat.id" name="{{ cat.name }}" type="checkbox" id="{{cat.name}}">
<label class="form-check-label" for="{{cat.name}}">
{{cat.name}}
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的组件
this.categories$ = this.storeService.getAllCategories().pipe(
map(result => (result as any).data),
tap(r => console.log(r))
)
Run Code Online (Sandbox Code Playgroud)
我的组件基本上从外部api获取类别列表