I am trying to add custom content in the popup template from a service returned results. The service function is working in the ngOninit() or in a custom function which is not a part of the popup template function. When ever using in the popup custom template function, the service is failed to collect the results.
Please find the code below (included only the major part), importing the custom service.
import { CustomService } from '../shared/service/custom.service';
constructor(private customService: CustomService){}
// Formation of the popup template
var popupTrailheads = {
title: "Unique id: {ID}",
content: this.getcustomcontent,
};
forming the feature layer the popup should come from this layer.
this.layer_fifteen = new FeatureLayer({
url: `${this.esriURL}/15`,
visible: true,
outFields: ['*'],
popupTemplate: popupTrailheads
});
The below function getcustomcontent() collects the details from the service.
public getcustomcontent(feature) {
// the service code
this.customService.getIdDetails(popup_id).subscribe((posts) => {
//required to get the result from the service
}
}
When I use try-catch, it shows 'TypeError: Cannot read property 'customService' of null'. How can I use service in popup template?