我有这种情况:-
我正在使用应用程序来获取数据的应用程序中创建一个customvalidator
import { AbstractControl } from '@angular/forms';
import { IndianStatesAndCitiesService } from './indianstatesandcities.service';
export function SpecificState(control: AbstractControl) {
let iss : IndianStatesAndCitiesService;
let getiss : string[] = [];
for(let i in iss.getStatesAndCities()){
getiss.push(i);
}
if (control.value !== undefined && (getiss.includes(control.value))) {
return { 'specificState': true };
}
return null;
}
但是它抛出以下错误:-
ERROR TypeError: Cannot read property 'getStatesAndCities' of undefined
at SpecificState (specificstate.validator.ts:6)
反正我可以在该函数内使用角度服务吗?
答案 0 :(得分:0)
替换此
let iss : IndianStatesAndCitiesService;
与
var iss = new IndianStatesAndCitiesService();
您尚未创建服务对象,请尝试