Nativescript Angular属性指令验证器AbstractControl.root.get无法正常工作

时间:2018-10-21 11:55:02

标签: nativescript angular2-nativescript nativescript-angular

属性指令验证器中的以下块返回空值。

import { Directive, Attribute } from '@angular/core';
import { Validator, AbstractControl, NG_VALIDATORS } from '@angular/forms';

@Directive({
  selector: '[validateEqual]',
  providers: [
    { provide: NG_VALIDATORS, useExisting: EqualValidatorDirective, multi: true }
  ]
})
export class EqualValidatorDirective implements Validator {

  constructor( @Attribute('validateEqual') public validateEqual: string, private page: Page) { }

  validate(c: AbstractControl): { [key: string]: any} {
    const v = c.value;

    const e = c.root.get(this.validateEqual);
    console.log(e);
    if ( e && v !== e.value ) {
      return { validateEqual: false};
    }
    return null;
  }

}

它没有在页面中返回文本框控件的期望值。

0 个答案:

没有答案