You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MAT-SELECTION-LIST与FormGroup绑定失效问题排查及解决

Fixing Unresponsive Mat-Selection-List Binding with FormGroup in Angular 6/Material 6

Hey, I've run into this exact scenario before—let's break down the issues and fixes step by step:

First: Fix the Obvious Typo

Your initial code has a critical typo that's breaking the binding right off the bat: formControlname should be formControlName (note the capitalized N). This is a super common gotcha, and fixing it will make the basic example work as expected.

Here's the corrected template code:

<form [formGroup]="clientForm">
 <h1> FormGroup Value </h1>
 <pre> {{ clientForm.get('myOtherControl').value | json }} </pre>
 <mat-selection-list id='2' formControlName="myOtherControl">
 <mat-list-option value="SOMETHING3"> SOMETHING3 </mat-list-option>
 <mat-list-option value="SOMETHING4"> SOMETHING4 </mat-list-option>
 </mat-selection-list>
</form>

Second: Address Dialog-Specific Layout Interference

If the typo fix didn't resolve your actual code issue (since you mentioned it was in a dialog), the problem likely stems from Flex layout placement. As you discovered, you shouldn't put fxLayout="row" on a div wrapping mat-list-option elements—move that attribute directly to the mat-selection-list tag instead.

The reason this breaks things is that nested Flex layout directives can interfere with the internal event listeners and value syncing logic of Mat-Selection-List, preventing the FormControl from picking up selection changes.

Adjusted structure for your dialog:

<form [formGroup]="clientForm">
  <mat-selection-list id='2' formControlName="myOtherControl" fxLayout="row">
    <!-- No wrapping div with fxLayout here -->
    <mat-list-option value="SOMETHING3"> SOMETHING3 </mat-list-option>
    <mat-list-option value="SOMETHING4"> SOMETHING4 </mat-list-option>
  </mat-selection-list>
</form>

Quick Debug Tips for Future Issues

If you run into similar binding problems later, these tricks can help you diagnose fast:

  • Add a valueChanges subscription to your FormControl to confirm if changes are being detected:
    this.clientForm.get('myOtherControl').valueChanges.subscribe(selectedValues => {
      console.log('Selected values updated:', selectedValues);
    });
    
  • Check your browser's console for Angular form binding errors—Angular usually logs clear messages for issues like misspelled control names or invalid nesting.

内容的提问来源于stack exchange,提问作者IrishDubGuy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:13:36