无法在角度5中使用模型对象进行验证

时间:2019-01-23 12:06:41

标签: html angular angular-ui-bootstrap

我在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之间的区别。两者都引用同一个对象。 ?

0 个答案:

没有答案