带有定义函数的@input的默认值

问题描述 投票:0回答:1

我想将默认值“checked”设置为mat-checkbox

@Input() set parkings(checked:boolean){
    //stuff
  }

还有我的HTML代码

<mat-checkbox checked [(ngModel)]="parkings">Parkings</mat-checkbox>

我想把它检查默认值

angular
1个回答
0
投票

只需添加一个get

private _parkings: boolean = true;
get parkings(): boolean {
  return this._parkings;
}
set parkings(checked: boolean) {
  // stuff to set _parkings.
}
© www.soinside.com 2019 - 2024. All rights reserved.