Hope someone might be able to help me on this. I have a json data like this which I get from the Url. The sample data is like this.
{
"home":
{
"landingPage": {
"title": "give some amount",
"desc1": "Give technical account details".
"desc2": "what is the time"
}
}
}
I need to use angular custom pipe to get the data. For Example: in app.component.html I would code as
{{home.landingpage.title | content }}
{{home.landingpage.desc1 | content }}
when I compile I should see "give some amount"
"Give technical account details" on my localhost.
update, I have been using the following pipe to get the data. But I am stuck at this point. I have a content pipe.ts
@Pipe({name: 'content'{)
export class contentPipe implements PipeTransform{
constructor(private readonly _dataService: DataService){}
transform(contentKey : string, args?: any): string {
const newContent = this._dataService.getContent();
return newContent;
}
My dataservice looks like this
@Injectable()
export class DataService{
expression: jsonata.Expression;
result: any;
constructor(
private readonly httpClient ; HttpClient,
)
{
this.actualContent()
}
getContent():any{
return this.result;
}
actualContent(): void {
this.httpClient.get<any>(href).subscribe((content => (
this.expression = jsonata("landingpage.title"),
this.result= this.expression.evaluate(content),
cosnole.log('result", this.result))); //this is printing the expected result. which is "give some amount" however when it is returned from getContent method it is always undefined.
}
I am not sure what is the mistake here but I am unable to return the value back to transform method in pipe.ts. It is always undefined.
Please help.