本文介绍了错误:初始化后无法更改选择的“多重"模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误图片:

 

<div class="pb-1"><md2-select placeholder="{{'WidgetType'|translate:lang}}" class="input_custom_width"(change)="widgetNode($event.value)" required><md2-option *ngFor="let widgetType of widgetTypeAry" [value]="widgetType.value">{{widgetType.name}}</md2-option></md2-select>

<div fxFlex.gt-lg="100" fxFlex="100" *ngIf="fieldsObj['node'] && showRequestAction" ><div class="pb-1"><md2-select placeholder="{{'Node'|translate:lang}}" [formControl]="editWidgetForm.controls['nodeId']" [(ngModel)]="nodeId" class="input_custom_width" [(multiple)]="isMultiNode" (change)="nodeChange($event.value)" required><md2-select-header><md-input-container class="input_custom_width"><input mdInput type="text" placeholder="{{'Search'| translate:lang}}" [ngModelOptions]="{standalone: true}" [(ngModel)]="searchNode"/></md-input-container></md2-select-header><md2-option *ngFor="let node of nodesAry | filterPipe : searchNode" [value]="node.value">{{ 节点名}}</md2-option></md2-select><small *ngIf="editWidgetForm.controls['nodeId'].hasError('required') &&editWidgetForm.controls['nodeId'].touched" class="mat-text-warn">{{'nodeReq'|translate:lang}}</small>

当我在选择下拉列表中使用 multiple 时它工作正常,但是当我使用 [multiple] 时,它只能在我的编辑表单中使用,而不能在添加表单中使用.并且它给出了上述错误 - 错误:无法更改 multiple 初始化后的选择模式.帮我整理一下.

解决方案

对于这个问题有一个非常丑陋的解决方法,在 *ngif=true 中扭曲你的 mat-select,并创建一个具有 multiple 属性的副本,包裹在一个 *ngif=!true 就在它下面

Error image:

 <div fxFlex.gt-lg="100" fxFlex="100" *ngIf="requestAction == 'add'">
                    <div class="pb-1">
                            <md2-select placeholder="{{'WidgetType'|translate:lang}}" class="input_custom_width"(change)="widgetNode($event.value)"  required>
                                <md2-option *ngFor="let widgetType of widgetTypeAry" [value]="widgetType.value">
                                    {{widgetType.name}}
                                </md2-option>
                            </md2-select>
                    </div>
                </div>
              <div fxFlex.gt-lg="100" fxFlex="100" *ngIf="fieldsObj['node'] && showRequestAction" >
                <div class="pb-1">
                    <md2-select placeholder="{{'Node'|translate:lang}}" [formControl]="editWidgetForm.controls['nodeId']" [(ngModel)]="nodeId" class="input_custom_width" [(multiple)]="isMultiNode" (change)="nodeChange($event.value)" required>
                        <md2-select-header>
                            <md-input-container class="input_custom_width">
                                <input mdInput type="text" placeholder="{{'Search'| translate:lang}}" [ngModelOptions]="{standalone: true}" [(ngModel)]="searchNode"/>
                            </md-input-container>
                        </md2-select-header>
                        <md2-option *ngFor="let node of nodesAry | filterPipe : searchNode" [value]="node.value">
                            {{ node.name }}
                        </md2-option>
                    </md2-select>
                    <small *ngIf="editWidgetForm.controls['nodeId'].hasError('required') && editWidgetForm.controls['nodeId'].touched" class="mat-text-warn">{{'nodeReq'|translate:lang}}</small>
                </div>
              </div>

When I use multiple in select dropdown it works fine but when I use [multiple] it only works in my edit form but not in add form .and it gives above error-Error: Cannot change multiple mode of select after initialization.help me to sort out this.

解决方案

There is a very ugly workaround for this problem, warp your mat-select in a *ngif=true, and create a duplicate with the multiple property, wrapped in a *ngif=!true just beneath it

这篇关于错误:初始化后无法更改选择的“多重"模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 20:58