Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS2339: Property 'subscribe' does not exist on type 'Subscription

Tags:

angular

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?

like image 744
Jayesh Vyas Avatar asked Oct 22 '25 01:10

Jayesh Vyas


1 Answers

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
        }

    }
like image 81
Jameer Khan Avatar answered Oct 24 '25 16:10

Jameer Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!