在Angular Material Design 6中,删除了(更改)方法.当用户更改选择时,我无法找到如何替换更改方法以执行组件中的代码谢谢!
Vto*_*one 242
把它改成change了selectionChange.
<mat-select (change)="doSomething($event)">
Run Code Online (Sandbox Code Playgroud)
就是现在
<mat-select (selectionChange)="doSomething($event)">
Run Code Online (Sandbox Code Playgroud)
https://material.angular.io/components/select/api
Jos*_*son 20
如果您使用的是Reactive表单,则可以像这样监听select控件的更改.
this.form.get('mySelectControl').valueChanges.subscribe(value => { ... do stuff ... })
Run Code Online (Sandbox Code Playgroud)
Kai*_*las 10
为了:
1) mat-select(selectionChange)="myFunction()"在 angular 中工作为:
示例.component.html
<mat-select placeholder="Select your option" [(ngModel)]="option" name="action"
(selectionChange)="onChange()">
<mat-option *ngFor="let option of actions" [value]="option">
{{option}}
</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)
样本.component.ts
actions=['A','B','C'];
onChange() {
//Do something
}
Run Code Online (Sandbox Code Playgroud)
2) 简单的 html 选择(change)="myFunction()"在 angular 中工作为:
示例.component.html
<select (change)="onChange()" [(ngModel)]="regObj.status">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
Run Code Online (Sandbox Code Playgroud)
样本.component.ts
onChange() {
//Do something
}
Run Code Online (Sandbox Code Playgroud)
对我来说(selectionChange),建议(onSelectionChange)不起作用,我没有使用ReactiveForms. 我最终做的是使用这样的(valueChange)事件:
<mat-select (valueChange)="someFunction()">
Run Code Online (Sandbox Code Playgroud)
这对我有用
我今天在 mat-option-group 上遇到了这个问题。解决我问题的方法是在 mat-select 的其他提供的事件中使用: valueChange
我在这里放了一些代码以供理解:
<mat-form-field >
<mat-label>Filter By</mat-label>
<mat-select panelClass="" #choosedValue (valueChange)="doSomething1(choosedValue.value)"> <!-- (valueChange)="doSomething1(choosedValue.value)" instead of (change) or other event-->
<mat-option >-- None --</mat-option>
<mat-optgroup *ngFor="let group of filterData" [label]="group.viewValue"
style = "background-color: #0c5460">
<mat-option *ngFor="let option of group.options" [value]="option.value">
{{option.viewValue}}
</mat-option>
</mat-optgroup>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
垫子版本:
“@角度/材料”:“^6.4.7”,
| 归档时间: |
|
| 查看次数: |
72068 次 |
| 最近记录: |