Using subscribe function getting cannot read undefined

cannot read property 'subscribe' of undefined unit test
cannot read property 'subscribe' of undefined observable
cannot read property 'asobservable' of undefined
cannot read property 'next' of undefined
cannot read property 'subscribe' of undefined react
typeerror: cannot read property 'subscribe' of undefined angular 8
cannot read property 'subscribe' of undefined observable jasmine
cannot read property 'subscribe' of undefined behaviorsubject

I am trying to get information from another component that sends HTTP request with youtube API and I get this problem:

Cannot read property 'subscribe' of undefined
at SafeSubscriber._next (profile.page.ts:20)

this the component code, from here I trying to get the information from the service:

  constructor(private db:FirebaseService,private afauth:AuthService) { 
  this.db.getDataObj("/Profile/" + this.uid).subscribe(res =>{
     this.profileInfo= res;
     this.afauth.getYoutubeData(res.channel).subscribe(data =>{
       console.log(data);
  })
})}

this the code of the function of the service that send the http request:

 getYoutubeData(ch):any{
  let m="https://www.googleapis.com/youtube/v3/channels? 
  part=snippet%2CcontentDetails%2Cstatistics&id=" + ch + "&key=" + api ;
  this.http.get(m).subscribe(data =>
  { 
   this.youtubeObj=data.items["0"].statistics;
   return this.youtubeObj;
 })

}

You need to correct your getYoutubeData method in the service by removing subscription and returning this.http.get. To get data.items["0"].statistics from subscription to getYoutubeData, use pipe & map operators:

import { catchError, map } from 'rxjs/operators';

getYoutubeData(ch): any {
  let m="https://www.googleapis.com/youtube/v3/channels? 
  part=snippet%2CcontentDetails%2Cstatistics&id=" + ch + "&key=" + api;
  return this.http.get(m).pipe(
    map(data => data.items["0"].statistics),
    catchError(err => {
      console.log(err);
    });
  )
}

Cannot read property 'subscribe' of undefined [SOLVED], Error in asynchronous validation: EXCEPTION: Cannot read property 'subscribe' of Cannot read property 'subscribe' of undefined [SOLVED] *ngIf=" registroFrm.get('usuarioInventiva').pending"> <p>Verificando en Inventiva. that anything returned out of them will be returned by the enclosing function. I have a service function which is returning Observable and I am consuming that service inside one of my components. I have written a unit test for the component using the technique posted here. However, strangely I am getting "cannot read property 'subscribe' of undefined". Component under test:

The problem here is that you can't basically return data from subscribe. So the solution here would be just returning an Observable and getting data in the constructor of the component.

.service.ts

 getYoutubeData(ch):any{
  let m="https://www.googleapis.com/youtube/v3/channels? 
  part=snippet%2CcontentDetails%2Cstatistics&id=" + ch + "&key=" + api ;
  return this.http.get(m);
}

*.component.ts

constructor(private db:FirebaseService,private afauth:AuthService) { 
  this.db.getDataObj("/Profile/" + this.uid).subscribe(res =>{
     this.profileInfo= res;
     this.afauth.getYoutubeData(res.channel).subscribe(data =>{
       console.log(data.items["0"].statistics);
  })
})}

Observable.subscribe do not work on server? `Cannot read property , `Cannot read property 'subscribe' of undefined` error on server error #905 When I start the server and make a request I get no response in the browser operator: FilterOperator { predicate: [Function], thisArg: undefined } }� Contact About Archives Advertise Jobs License Subscribe Guest Posting. Cannot read property 'foo' of undefined. i will using utility function like that.

You already subscribe in getYoutubeData method. You can only subscribe once. In your method please use pipe and tab method like :

getYoutubeData(ch):any{
  let m="https://www.googleapis.com/youtube/v3/channels? 
  part=snippet%2CcontentDetails%2Cstatistics&id=" + ch + "&key=" + api ;
  return this.http.get(m).pipe(tap(data =>
  { 
   this.youtubeObj=data.items["0"].statistics;
   return this.youtubeObj;
 }))
}

"Cannot read property 'subscribe' of undefined" when store creation , you get the error "Cannot read property 'subscribe' of undefined" in a store with a 'subscribe' method`); } } export function subscribe(store,� Cannot read matched of undefined when using router file. 0. JavaScript function that flips brackets direction To subscribe to this RSS feed, copy and paste

What Am I'm doing Wrong with Observables and Services? : Angular2, getting the type error: ERROR TypeError: Cannot read property 'subscribe' of undefined The Account service has a Data service that gets injected. The Data � I am trying to get background music playing behind my game using p5.js. However, I have tried every variation I can possibly think of, trying new Audio, not having preLoad, etc. And whatever I do I still get the. Uncaught TypeError: Cannot read property 'play' of undefined" on my backgroundMusic.play();

Using subscribe function getting cannot read undefined, I am trying to get information from another component that sends HTTP request with youtube API and I get this problem: Cannot read property 'subscribe' of� Angular 2 Cannot read property 'subscribe' of undefined TypeError: Cannot read property 'subscribe' of undefined. Ask Question Asked 3 years, 2 months ago.

Troubleshooting � redux-observable, switchMap is not a function. Version v1.0.0 of redux-observable requires RxJS v6 , which uses pipeable operators instead of prototype-based methods So if you' re using rxjs-compat (or using a pre-1.0 version of redux-observable), and still getting an error like this TypeError: Cannot read property 'subscribe' of undefined. Each anonymous function creates additional closure, in your case it's enclosed in subscribe, ant this closure will be opened by default by VS Code when your breakpoint will be hit. And please try to avoid this old-style JS hacking let that = this e.c.t, because when you on TypeScript, Classes, ES6 and arrow functions those hacks are just not

Comments
  • You cannot return data from within subscribe like that, it won’t actually return data. You instead can use RxJS operators such as map() inside of pipe() to pass formatted observable stream data to other methods.
  • Do you mean tap method?