Property 'subscribe' does not exist on type 'OperatorFunction<{}, {}>'

Asked
Active3 hr before
Viewed126 times

8 Answers

operatorfunctionexistpropertysubscribe
90%

When you set a type or any to the results, do the error still pop?,That’s a typescript error displayed from your editor I guess, no?,I’m working on a http provider, The issue is with the subscribe module after mapping the json response

Example_snippet/controller/utility/_operatorfunction.js/ import { HttpClient } from '@a. . .
import {
   HttpClient
} from '@angular/common/http';
import {
   Injectable
} from '@angular/core';
import {
   Http
} from '@angular/http';
import {
   Observable
} from 'rxjs/Observable';
import 'rxjs/add/operator/map';

/*
  Generated class for the PostsProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class PostsProvider {
   data: any = null;

   constructor(public http: HttpClient) {
      console.log('Hello PostsProvider Provider');
      // this.load();
   }

   load() {
      if (this.data) {
         // already loaded data
         return Promise.resolve(this.data);
      }

      // don't have the data yet
      return new Promise(resolve => {
         // We're using Angular HTTP provider to request the data,
         // then on the response, it'll map the JSON data to a parsed JS object.
         // Next, we process the data and resolve the promise with the new data.
         this.http.get('https://randomuser.me/api/?results=10')
            .map((res => res.json())
               .subscribe(data => {
                  // we've got back the raw data, now generate the core schedule data
                  // and save the data for later reference
                  this.data = data.results;
                  resolve(this.data);
               }));
      });
   }

}
load more v
88%

"Property 'subscribe' does not exist on type 'OperatorFunction'",You are calling subscribe on your HTTP call in the getRecipes method, The return value of subscribe is of type Subscription, not Observable

Example_snippet/controller/utility/_operatorfunction.js/ import { Injectable } from '@a. . .
import {
   Injectable
} from '@angular/core';
import {
   HttpClient,
   HttpResponse
} from '@angular/common/http';
import {
   Response
} from '@angular/http';
import {
   RecipeService
} from '../recipes/recipe.service';
import {
   Recipe
} from '../recipes/recipe.model';
import {
   map
} from 'rxjs/operators';

@Injectable({
   providedIn: 'root'
})
export class DataStorageService {

   constructor(private httpClient: HttpClient,
      private recipeService: RecipeService) {}

   storeRecipes() {
      return this.httpClient.put('https://ng-recipe-10b53.firebaseio.com/recipes.json',
         this.recipeService.getRecipes());
   }

   getRecipes() {
      this.httpClient.get('https://ng-recipe-book.firebaseio.com/recipes.json');
      map(
            (response: Response) => {
               const recipes: Recipe[] = response.json();
               for (const recipe of recipes) {
                  if (!recipe['ingredients']) {
                     recipe['ingredients'] = [];
                  }
               }
               return recipes;
            }
         )
         .subscribe(
            (recipes: Recipe[]) => {
               this.recipeService.setRecipes(recipes);
            }
         );
   }

}
load more v
72%

Search Answer Titles

Example_snippet/controller/utility/_operatorfunction.js/ import { of } from 'rxjs'; . . .
import {
   of
} from 'rxjs';
load more v
65%

ERROR in src/app/device-list/device-list,component

Example_snippet/controller/utility/_operatorfunction.js/ get(searchTerm) { const ap. . .
get(searchTerm) {
   const apiLink = this.giphyApi + searchTerm;
   return this.http.get(apiLink).map((response: any) => {
      if (this.apiKey === 'api-key') {
         // Use undefined image
         return '';
      }

      if (response.data.length > 0) {
         return response.data[0].images.original.url;
      } else {
         return 'https://media.giphy.com/media/YaOxRsmrv9IeA/giphy.gif'; // dancing cat for 404
      }
   });
}
load more v
75%

When writing http code in Angular, it is a common patter to map the response Observable, e,g

Example_snippet/controller/utility/_exist.js/ this.http.post(uploadUrl, form. . .
this.http.post(uploadUrl, formData).map((res: Response) => res.json())
load more v
40%

You are not calling the getVideos method, You are calling subscribe on the function reference of getVideos and not the returned value

Example_snippet/controller/utility/_exist.js/ ngOnInit() { this.videoser. . .
ngOnInit() {
   this.videoserv.getvideos().subscribe((response) => {
      this.videos = response
   });
}
load more v
22%

I have subscribed to data which I want to pipe, But somehow it does not work

Example_snippet/controller/utility/_exist.js/ authenticationState = new Be. . .
  authenticationState = new BehaviorSubject(false);
  ...
  checkToken() {
     this.storage.get(TOKEN_KEY).then(access => {
        if (access) {
           this.user = this.helper.decodeToken(access);
           this.authenticationState.next(true);
        }
     });
  }
load more v
60%

I made this code snippet for you to try it out, hope it does what you need,It seems you have a misplaced parenthesis in your common,service

Example_snippet/controller/utility/_exist.js/ import {Injectable} from '@ang. . .
import {
   Injectable
} from '@angular/core';
import {
   Http,
   Response
} from '@angular/http';
import {
   Observable
} from 'rxjs/Observable';
import {
   catchError,
   map
} from 'rxjs/operators';
import 'rxjs/add/operator/do';
import 'rxjs/Rx';

@Injectable()
export class CommonService {

   constructor(private http: Http) {}

   GetProcesses() {
      let url = 'http://localhost:4000/getProcesses/';
      return this.http.get(url).pipe(
         map((response: Response) => response.json()),
         catchError(error => Observable.of(null))
      );
   }
}