html
<select class="form-control form-control-sm" formControlName="appDeptId" [(ngModel)]="appDeptId"
(change)="getAppClinics()">
<option [value]=null>Please Select</option>
<option *ngFor="let type of appDepartments" [value]="type.deptId">{{type.deptName}}
</option>
</select>ts
appDeptId: number;
getAppClinics(){
if (this.appDeptId != null) { // if fails for null
console.log("this.appDeptId :"+this.appDeptId); // this displays null
}在这里,即使appDeptId id的值为null,它仍然会输入if条件并输出null。我怎么才能解决这个问题。
发布于 2019-10-16 18:31:24
if条件是get null as string,所以实际上是在比较null!='null',所以将条件更改为
if(deviceValue != null && deviceValue != 'null'){ 应该行得通
发布于 2019-10-16 18:40:26
appDeptId: number;
getAppClinics(){
if (this.appDeptId != null && this.appDeptId != undefined) { // if fails for null
console.log("this.appDeptId :"+this.slotSearch.appDeptId); // this displays null
}https://stackoverflow.com/questions/58410991
复制相似问题