函数定义的@input的默认值

时间:2019-03-29 18:44:49

标签: angular

我想将默认值“ checked”放入mat-checkbox

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

还有我的HTML代码

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

我想将其设置为默认值

1 个答案:

答案 0 :(得分:0)

只需添加一个get

private _parkings: boolean = true;
get parkings(): boolean {
  return this._parkings;
}
set parkings(checked: boolean) {
  // stuff to set _parkings.
}