Mark Beynon
Mark Beynon

Reputation: 265

Angular 6 rxjs pipe not returning data

I have an issue when using the latest version of rxjs with Angular 6. The code;

import { Observable, throwError } from "rxjs";
import { map, filter, catchError, mergeMap } from 'rxjs/operators';

isValidUser(user, password) : Observable<any> {

let urlString = "http://localhost....=" + user + "&password=" + password;

console.log(urlString)

return this._http.get(urlString, {withCredentials: true, responseType: 'json'})
.pipe(
  map((val: any[]) => {
    console.log("val",val);
    if (val.hasOwnProperty("GoldUser")) {
      if (val["GoldUser"][0]["_Qy"] == "GoldSecurityUser")
        this.isUserLoggedIn = true;
        return true;
      }
      return false;
  }), catchError( error => {
    console.log("error",error );
    return throwError( 'Something went wrong!' )
  })

);

}

The problem is that even though the URL is valid and a simple browser rest call returns json data, the code returns nothing. It never hits my console.log val statement. In Chrome the developer tools Network tab shows no activity either. This is my first time using the Angular6 and rxjs V6 pipe and I'm a bit stumped by this this.

Any help would be greatly appreciated.

ng --version

Angular CLI: 6.0.8
Node: 8.9.4
OS: win32 x64
Angular: 6.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8 
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cli                      6.0.8
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.1
typescript                        2.7.2
webpack                           4.8.3

By the way, I've looked atthe rxjs migration page but still can't see what I've done incorrectly...

Thanks,

Mark.

Upvotes: 2

Views: 2402

Answers (1)

Maxime Michaud
Maxime Michaud

Reputation: 141

You need to call subscribe on the observable to execute the request.

https://angular.io/guide/observables#subscribing

Upvotes: 5

Related Questions