我做了一个自定义验证指令来验证唯一的永久链接。这段代码工作正常,但是当我尝试为生产创建构建时,它给了我以下错误:-
错误:无法解析 E:/Manish/Projects/ampleAdmin/src/app/shared/permalink-validation.directive.ts: ([object Object], ?) 中 UniquePermalinkValidatorDirective 的所有参数。
永久链接-validation.directive.ts
import { Directive } from '@angular/core';
import { AsyncValidator, AbstractControl, ValidationErrors, NG_ASYNC_VALIDATORS, AsyncValidatorFn } from '@angular/forms';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import * as qs from 'qs';
import { PageService } from '../services/page.service';
import { IPage } from '../client-schema';
export function UniquePermalinkValidator(pageService: PageService, page: IPage): AsyncValidatorFn {
return (ctrl: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null> => {
if (!(ctrl && ctrl.value)) { return null; }
const cond: any = {
where: {
permalink: ctrl.value
}
};
if (page && page.id) {
cond.where.id = { nin: [page.id]};
}
const query = qs.stringify(cond, { addQueryPrefix: true });
return pageService.getPageCount(query).pipe(
map(res => {
return res && res.count ? { uniquePermalink: true } : null;
})
);
};
}
@Directive({
selector: '[appUniquePermalink]',
providers: [{ provide: NG_ASYNC_VALIDATORS, useExisting: UniquePermalinkValidatorDirective, multi: true }]
})
export class UniquePermalinkValidatorDirective implements AsyncValidator {
constructor(private pageService: PageService, private page: IPage) { }
validate(ctrl: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null> {
return UniquePermalinkValidator(this.pageService, this.page)(ctrl);
}
}
墨色风雨
相关分类