[英]Two way binding on angular material slide toggle not working as expected (Angular 4)
我已經實現了所有似乎都可以工作的角度材料滑動切換,但出於某種原因它沒有將值綁定到相關變量?
// other irrevelant imports above..
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
@Component({
selector: 'app-calendar',
templateUrl: './calendar.component.html',
styleUrls: ['./calendar.component.scss'],
host: {
'(document:click)': 'handleClickEvent($event)',
}
})
export class CalendarComponent implements OnInit {
filteringSchedule: boolean = false;
filteringSent: boolean = false;
filteringFailed: boolean = false;
}
// 組件
<mat-slide-toggle
class="calendar-filter-types"
[ngModel]="(filteringSchedule)"
[color]=""
[checked]="">
Scheduled : {{ filteringSchedule }}
</mat-slide-toggle>
一旦我選中或取消選中切換,我會期望filteringSchedule
值相應地更改為 true 或 false 嗎? 但是,在組件中,由於某些未知原因,它始終保持為false
- 任何人都可以提出為什么會這樣?
我是角 4
只需將您的 html 更新為
[(ngModel)]="filteringSchedule"
[ngModel]="(filteringSchedule)"
將此更改為:
[(ngModel)]="filteringSchedule"
這適用於 Angular8+
[(ngModel)]="filteringSchedule"
並確保您已經導入 FormsModule
import {FormsModule} from '@angular/forms';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.