javascript - 无法在 mat-select 中更新 inputCtrlState 的值
问题描述
<mat-select #autoType="matSelect" tabindex="-1" [(ngModel)]="multipleSelect" multiple [placeholder]="placeholderText" title="{{getToolTipDEata()}}" (selectionChange)="onMultiSelectionEvent($event)">
<div class="box-search">
<input #autofocus matInput [placeholder]="placeholderText" [(ngModel)]="inputCtrlState" [matAutocomplete]="autoType" (keydown)="keyDownElement($event)" (keyup)="dynamicOnKeyUp($event)" (focus)="onFocus(val.partnerName==undefined?val:val.partnerName)" [disabled]="fieldDisabled" >
<button mat-button *ngIf="inputCtrlState && !fieldDisabled" matSuffix mat-icon-button aria-label="Clear" (click)="clearAutoCompleteTxt()">
<mat-icon>close</mat-icon>
</button>
<mat-autocomplete #autoType="matAutocomplete" [displayWith]="displayFn">
</mat-autocomplete>
</div>
<mat-select-trigger>
{{multipleSelect.length>0 ? multipleSelect[0]['desc'] : ''}}
<span *ngIf="multipleSelect?.length > 1" class="example-additional-selection">
(+{{multipleSelect.length - 1}} {{multipleSelect.length > 2 ? 'other' : 'others'}})
</span>
<!--MLT-->
</mat-select-trigger>
<mat-option style="display: none;">
Search Results
</mat-option>
<mat-option *ngFor="let dropdownValue of _localServicedData" [value]="dropdownValue" >
{{dropdownValue.desc}}
</mat-option>
</mat-select>
clearAutoCompleteTxt(){
this.inputCtrlState=''
}
此函数在同一组件中定义,但值未更新。我正在尝试使用现有的 mat-select 组件创建自定义组件。
解决方案
<mat-select style="overflow: hidden" #autoType="matSelect" tabindex="-1" [(ngModel)]="multipleSelect" multiple
[placeholder]="placeholderText" title="{{getToolTipDEata()}}" (selectionChange)="onMultiSelectionEvent($event)">
<mat-select-trigger>
{{multipleSelect.length>0 ? multipleSelect[0]['desc'] : ''}}
<span *ngIf="multipleSelect?.length > 1" class="example-additional-selection">
(+{{multipleSelect.length - 1}} {{multipleSelect.length > 2 ? 'other' : 'others'}})
</span>
</mat-select-trigger>
<div class="box-search">
<input name="mytemp" #mytemp="ngModel" #autofocus matInput [placeholder]="placeholderText" (blur)="onBlur()"
[(ngModel)]="inputCtrlState"
[matAutocomplete]="autoType"
(keydown)="keyDownElement($event)"
(keyup)="dynamicOnKeyUp($event)"
(focus)="dynamicOnKeyUp($event)"
(focus)="onFocus(val.partnerName==undefined?val:val.partnerName)"
[disabled]="fieldDisabled" >
<button mat-button *ngIf="inputCtrlState && !fieldDisabled" matSuffix mat-icon-button aria-label="Clear" (click)="clearAutoCompleteTxt()">
<mat-icon>clear</mat-icon>
</button>
<mat-autocomplete #autoType="matAutocomplete" [displayWith]="displayFn">
</mat-autocomplete>
</div>
<div style="overflow-y: auto; max-height:200px">
<mat-option style="display: none;">
Search Results
</mat-option>
<mat-option *ngFor="let dropdownValue of _localServicedData" [value]="dropdownValue" >
{{dropdownValue.desc}}
</mat-option>
</div>
</mat-select>
I found one solution, onBlur i am clearing the inputctrl value.
推荐阅读
- stripe-payments - 条带化自定义成功页面客户端
- r - 您可以在 R 中使用 rename() 通过引用存储字符串的变量来重命名变量吗?
- python - isinstance() 函数是否不足以检测整数和浮点数?
- javascript - 部分执行查询并返回值jQuery php
- swift - 在我的 Swift 包中使用时没有这样的模块“组合”
- r - 使用 actionButton 在 plotly 条形图和 plotly 柱形图之间切换
- python - 按列分组,但返回数据框作为初始数据框 - 熊猫
- java - 具有多个数组返回的字符串拆分
- arrays - 如果两个数组的内容彼此不同,为什么这两个数组之间的比较不起作用?
- c# - ASP.NET - 无法取消保护 message.State 只有一个回调