I need to find province name from angular so I write a pipe service for find name with code this is my code pipe
export class ConvertStatePipe implements PipeTransform {
constructor(private callData: CallDataService) {}
transform(value: string): any {
let nameProvince = '';
this.callData.getAllProvinces().subscribe( (res) => {
for (const item of res.provinces) {
if (item.provinceCode === value) {
nameProvince = item.name;
}
}
});
return nameProvince;
}
here I called CallDataService, from CallDataService I have a function Which is called getAllProvinces, I take all Provinces from API now I set for because I need to find Province name and return name from HTML this my HTML code
<div class="mb-24 terminal-item" fxFlex="33.33333%">
<strong>Province</strong>
{{userData.state | convertState }}
</div>
but I can`t retunr variable nameProvince because this undefined and i think because this.callData.getAllProvinces() not async, are you have any idea ?