使用MAT-RADIO组的嵌套无线电按钮在角度

发布于 2025-02-01 11:36:25 字数 1621 浏览 3 评论 0原文

我试图用嵌套的JSON数组显示嵌套的广播按钮。但是它无法正常工作。

 <mat-radio-group aria-label="Select an option" formControlName="investmentCategory" fxLayout="column">                                        
                                    <mat-radio-button   *ngFor="let category of investmentCategory" [value]="category.Investment_Category"
                                        [matTooltip]="">{{category.Investment_Category}}                                                                                       
                                            <mat-radio-group *ngIf="showSubCategory " aria-label="Select an option" formControlName="subInvestmentCat" fxLayout="column">                                        
                                                <mat-radio-button  [checked]="false" *ngFor="let subCat of category.Sub_Category" [value]="subCat.Sub_Category"
                                                    [matTooltip]="">{{subCat.Sub_Category}}                                                    
                                                </mat-radio-button>    
                                            </mat-radio-group>                                              
                                    </mat-radio-button>
                                   
                                </mat-radio-group>

输出越来越多。

有人可以帮我。提前致谢。

I am trying to display nested radio button with an nested json array. But its not working as expected.

 <mat-radio-group aria-label="Select an option" formControlName="investmentCategory" fxLayout="column">                                        
                                    <mat-radio-button   *ngFor="let category of investmentCategory" [value]="category.Investment_Category"
                                        [matTooltip]="">{{category.Investment_Category}}                                                                                       
                                            <mat-radio-group *ngIf="showSubCategory " aria-label="Select an option" formControlName="subInvestmentCat" fxLayout="column">                                        
                                                <mat-radio-button  [checked]="false" *ngFor="let subCat of category.Sub_Category" [value]="subCat.Sub_Category"
                                                    [matTooltip]="">{{subCat.Sub_Category}}                                                    
                                                </mat-radio-button>    
                                            </mat-radio-group>                                              
                                    </mat-radio-button>
                                   
                                </mat-radio-group>

Output is getting like below.
enter image description here

Can someone help me out. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风挽心 2025-02-08 11:36:26

您可以通过将子组放置在内部的按钮外部,可以避免此问题:

<mat-radio-group aria-label="Select an option" formControlName="investmentCategory" fxLayout="column">

    <mat-radio-button   *ngFor="let category of investmentCategory" [value]="category.Investment_Category" [matTooltip]="">
        {{category.Investment_Category}}                                                                                       
    </mat-radio-button>

    <mat-radio-group *ngIf="showSubCategory " aria-label="Select an option" formControlName="subInvestmentCat" fxLayout="column">                                        

        <mat-radio-button  [checked]="false" *ngFor="let subCat of category.Sub_Category" [value]="subCat.Sub_Category" [matTooltip]="">
            {{subCat.Sub_Category}}                                                    
        </mat-radio-button>    

    </mat-radio-group>

</mat-radio-group>

You can avoid this problem by placing the sub-group outside the button not inside:

<mat-radio-group aria-label="Select an option" formControlName="investmentCategory" fxLayout="column">

    <mat-radio-button   *ngFor="let category of investmentCategory" [value]="category.Investment_Category" [matTooltip]="">
        {{category.Investment_Category}}                                                                                       
    </mat-radio-button>

    <mat-radio-group *ngIf="showSubCategory " aria-label="Select an option" formControlName="subInvestmentCat" fxLayout="column">                                        

        <mat-radio-button  [checked]="false" *ngFor="let subCat of category.Sub_Category" [value]="subCat.Sub_Category" [matTooltip]="">
            {{subCat.Sub_Category}}                                                    
        </mat-radio-button>    

    </mat-radio-group>

</mat-radio-group>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文