【发布时间】:2019-02-01 02:45:23
【问题描述】:
我有一个 if 块,如下所示:
if (this.totalTenants === 1) {
this.newTenants.tenant2 = Object.assign({ name: null, number: null }, this.emptyTenant);
this.newTenants.tenant3 = Object.assign({ name: null, number: null }, this.emptyTenant);
this.newTenants.tenant4 = Object.assign({ name: null, number: null }, this.emptyTenant);
this.newTenants.tenant2 = this.emptyTenant;
this.newTenants.tenant3 = this.emptyTenant;
this.newTenants.tenant4 = this.emptyTenant;
this.newTenants.rentAmount = 3200;
}
但是当 this.totalTenants 的值为 1 时,它不会进入 if 块。
我正在使用 typescript 开发 Angular 6。
如果我 if (this.totalTenants == 1) 双等号 ==
然后执行 if 块,但我收到如下所示的错误: [tslint] == 应该是 ===(三等号)
【问题讨论】:
-
在 this.totalTenants 之前添加一个加号 (+),例如 if (+this.totalTenants === 1){....}
-
添加
console.log(this.totalTenants)以确保totalTenants是一个整数。
标签: if-statement angular6 typescript3.0