我在angular5和bootstrap中有一段代码:
<div class="form-group" [class.has-error]="isActive.touched && isActive.invalid ">
<label>Active?</label>
<div class="form-control">
<label class="checkbox-inline">
<input [required]="employee.isActive==null" type="checkbox"
[(ngModel)]= "employee.isActive" #isActive="ngModel"
name="isActive">
isActive
</label>
</div>
<span class="help-block" *ngIf="isActive.errors?.required && isActive.touched">
IsActive is required
</span>
</div>
它的作用是突出显示“必须处于活动状态”文本,如果我将employee.isActive==null
替换为isActive.value==null
,则代码可以正常工作,但是如果我使用employee.isActive.value==null
,则代码将失败,此处员工是模型对象:
employee:Employee[]=[{ id: null,
name: null,
gender: null,
email: null,
phoneNumber: null,
contactPreference: null,
dateOfBirth: null,
department: null,
isActive: null,
photoPath: null}];
我无法获得employee.isActive和isActive之间的区别。两者都引用同一个对象。 ?