(onSelectionChange) 调用函数并发送值 [Angular Material](未定义)
(onSelectionChange) call a function and send the value [Angular Material] (undefiend)
我很乐意得到你的帮助。
我尝试获取所选项目的值并将值发送给函数。
组件html:
<mat-form-field style="text-align: right">
<input type="text" placeholder="type..." matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option (onSelectionChange)="selected($event)" *ngFor="let option of filteredOptions | async" [value]="option.companyName">
{{option.companyName}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
组件 ts:
// Selected option function triger
selected(event: MatAutocompleteSelectedEvent) {
console.log(event);
}
事件调用了函数但控制台不安全
在 mat-autocomplete
元素上使用 optionSelected
。
<mat-autocomplete #auto="matAutocomplete" (optionSelected)='selected($event.option.value)'>
// Selected option function triger
selected(value: string) {
console.log(value);
}
我很乐意得到你的帮助。 我尝试获取所选项目的值并将值发送给函数。
组件html:
<mat-form-field style="text-align: right">
<input type="text" placeholder="type..." matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option (onSelectionChange)="selected($event)" *ngFor="let option of filteredOptions | async" [value]="option.companyName">
{{option.companyName}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
组件 ts:
// Selected option function triger
selected(event: MatAutocompleteSelectedEvent) {
console.log(event);
}
事件调用了函数但控制台不安全
在 mat-autocomplete
元素上使用 optionSelected
。
<mat-autocomplete #auto="matAutocomplete" (optionSelected)='selected($event.option.value)'>
// Selected option function triger
selected(value: string) {
console.log(value);
}