属性指令验证器中的以下块返回空值。
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;
}
}
它没有在页面中返回文本框控件的期望值。