I am facing one problem while working in Angular 8.
service.ts file
public getTopicsByContainerId(containerId) {
var result;
if (this.envUrl.accessMock == true) {
result = topicsData;
return of(result.filter(items => items.attributes.ContainerOid == containerId));
}
else {
var url = this.getTopicsByContainerIdEndPoint.replace("{id}", containerId);
return this.repository.getData(url).subscribe();
}
}
component.ts file
var output = this.homeService.getTopicsByContainerId(container_Oid).subscribe(res => {
this.currentContainerTopics = res[0];
});
Now the problem is that I am facing the following error while calling the web service from the component file.
ERROR in src/app/home/home.component.ts(98,72): error TS2339: Property 'subscribe' does not exist on type 'Subscription | Observable<any>'.
Property 'subscribe' does not exist on type 'Subscription'.
can anyone tell me where I am doing mistake?
Remove .subscribe()
public getTopicsByContainerId(containerId) {
var result;
if (this.envUrl.accessMock == true) {
result = topicsData;
return of(result.filter(items => items.attributes.ContainerOid == containerId));
}
else {
var url = this.getTopicsByContainerIdEndPoint.replace("{id}", containerId);
// return this.repository.getData(url).subscribe(); // remove this line
return this.repository.getData(url); // this method should return Observable response
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With