去除角度6材料垫选择更改方法

时间:2018-05-07 21:31:13

标签: angular angular6

在Angular Material Design 6中,删除了(更改)方法。 当用户更改选择时,我无法找到如何替换更改方法以在组件中执行代码 谢谢!

6 个答案:

答案 0 :(得分:160)

将其从change更改为selectionChange

<mat-select (change)="doSomething($event)">

现在是

<mat-select (selectionChange)="doSomething($event)">

https://material.angular.io/components/select/api

答案 1 :(得分:13)

如果你正在使用Reactive表单,你可以像这样监听select控件的更改。

this.form.get('mySelectControl').valueChanges.subscribe(value => { ... do stuff ... })

答案 2 :(得分:4)

针对:

1)垫选String stringValue = "Those who had coins, enjoyed in the rain, those who had notes were busy looking for the shelter"; String ValueSplitByColon[] = stringValue.split(","); String firstValue = ValueSplitByColon[0]; String secondValue = ValueSplitByColon[1]; String thirdValue = ValueSplitByColon[2]; txtV1.setText(firstValue); txtV2.setText(secondValue; txtV3.setText(thirdValue; 的工作角度如下:

sample.component.html

(selectionChange)="myFunction()"

sample.component.ts

 <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>

2)简单的html select actions=['A','B','C']; onChange() { //Do something } 可以按如下方式工作:

sample.component.html

(change)="myFunction()"

sample.component.ts

<select (change)="onChange()" [(ngModel)]="regObj.status">
    <option>A</option>
    <option>B</option>
    <option>C</option>
</select>

答案 3 :(得分:1)

我今天在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>

垫子版本:

“ @角度/材料”:“ ^ 6.4.7”,

答案 4 :(得分:0)

对我来说(selectionChange)和建议的(onSelectionChange)无效,并且我没有使用ReactiveForms。我最终要做的是使用(valueChange)事件,例如:

<mat-select (valueChange)="some function()">

这对我有用

答案 5 :(得分:0)

对我来说,...(click)="myFunction()"... 有效;上面什么都没有。