【发布时间】:2019-04-21 18:00:25
【问题描述】:
我有一个对象:
export class ReccurrenceModel {
fromDate: Date;
toDate: Date;
weeklyReccurrence: number;
state: State;
isMonday: boolean;
isTuesday: boolean;
isWednesday: boolean;
isThursday: boolean;
isFriday: boolean;
fromDateToReturn: Date;
toDateToReturn: Date;
}
我是这样用的
if (this.reccurrenceSelected === true) {
this.reccurrence.isMonday = this.mondaySelected;
this.reccurrence.isTuesday = this.tuesdaySelected;
this.reccurrence.isWednesday = this.wednesdaySelected;
this.reccurrence.isThursday = this.thursdaySelected;
this.reccurrence.isFriday = this.fridaySelected;
}
我想为它们设置一个默认值 - false 因为如果我不在 UI 中设置它们,它们将是未定义的,我不希望这样。
如何在 typescript 中设置布尔值的默认值?
【问题讨论】:
-
试试
isMonday:boolean = false; -
可能是
variabelName = false,是吗? -
@FatemeFazli 这给出了冗余的 lint 错误(只是为了通知)
-
@FatemeFazli 这也是不推荐的方式
-
@trichetriche,PardeepJain 谢谢。
标签: angular typescript boolean