How to return only single value when services are injecting into the pipes?
This is the code of html file where i am using the pipe.
{{model.template[i].locale | locale }}
Locale.pipe.ts file. when i console the result it prints only single value.bur does not return anything in html file.
import { Pipe, PipeTransform } from '@angular/core';
import { UserService } from '../../core/@services/user.service'
@Pipe({ name: 'locale' })
export class Locale implements PipeTransform {
returnresponse: string;
constructor(private UserService: UserService) { }
transform(value: any) {
this.UserService.lookupapi_code(value).subscribe(result => {
console.log(result)
//this.returnresponse = result;
return result;
});
// return this.returnresponse;
}
}
User.service.ts file which return only single value from here
public lookupapi_code(languagecode): Observable<any> {
return this.http.get(AppSettings.lookupapi).map((response: Response) => {
var Jstring = JSON.stringify(response);
var Jarray = JSON.parse(Jstring);
for (var i = 0; i < Jarray.length; i++) {
if (Jarray[i].locale == languagecode) {
return Jarray[i].displayName;
}
}
});
}