Angular 6 재료 매트 선택 변경 방법 제거
각도 재료 설계 6에서는 (변경) 방법이 제거되었습니다.사용자가 선택을 변경할 때 구성 요소에서 코드를 실행하기 위해 변경 방법을 어떻게 교체해야 합니까?
에서 변경되었습니다.change로.selectionChange.
<mat-select (change)="doSomething($event)">
지금은
<mat-select (selectionChange)="doSomething($event)">
https://material.angular.io/components/select/api
반응형 양식을 사용하는 경우 선택 컨트롤의 변경 내용을 들을 수 있습니다.
this.form.get('mySelectControl').valueChanges.subscribe(value => { ... do stuff ... })
대상:
매트 셀렉트(selectionChange)="myFunction()"각도가 다음과 같이 작동합니다.
sample.component.component.cisco
<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>
sample.component.ts
actions=['A','B','C'];
onChange() {
//Do something
}
단순 html 선택(change)="myFunction()"각도가 다음과 같이 작동합니다.
sample.component.component.cisco
<select (change)="onChange()" [(ngModel)]="regObj.status">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
sample.component.ts
onChange() {
//Do something
}
나를 위해.(selectionChange)및 제안된(onSelectionChange)작동하지 않았고 사용하지 않고 있습니다.ReactiveForms결국 제가 하게 된 것은(valueChange)다음과 같은 이벤트:
<mat-select (valueChange)="someFunction()">
그리고 이것은 나에게 효과가 있었습니다.
저는 오늘 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>
매트 버전:
"@matrix/material": "^6.4.7",
나를 위해....(click)="myFunction()"...작동했습니다. 위에서 온 것이 없습니다.
<매트-선택(변경)="doSomething($event)""
이제는 <매트 선택(선택 변경)="doSomething($event)""
언급URL : https://stackoverflow.com/questions/50222738/angular-6-material-mat-select-change-method-removed
'programing' 카테고리의 다른 글
| NVM을 사용하여 기본 노드 버전을 설정하는 방법은 무엇입니까? (0) | 2023.05.09 |
|---|---|
| 열의 마지막 비어 있지 않은 셀 (0) | 2023.05.09 |
| 이해하는 시간.perf_counter() 및 time.process_time() (0) | 2023.05.09 |
| SQL Server 데이터베이스에서 ID 증가가 점프하고 있습니다. (0) | 2023.05.09 |
| "리모트에 로컬에 없는 작업이 포함되어 있어 업데이트가 거부되었습니다." 오류 (0) | 2023.05.09 |