After updating to Angular 6, I encountered this error. While I found documentation on using .pipe(), I'm unsure how to implement it when there are multiple .map() functions as shown below. Your assistance would be greatly appreciated...
import {Injectable} from '@angular/core';
import {Http, Headers} from '@angular/http';
import 'rxjs/add/operator/map';
import {TOKEN_AUTH_PASSWORD, TOKEN_AUTH_USERNAME} from '../services/auth.constant';
@Injectable()
export class AuthenticationService {
static AUTH_TOKEN = '/oauth/token';
constructor(private http: Http) {
}
login(username: string, password: string) {
const body = `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}&grant_type=password`;
const headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append('Authorization', 'Basic ' + btoa(TOKEN_AUTH_USERNAME + ':' + TOKEN_AUTH_PASSWORD));
return this.http.post(AuthenticationService.AUTH_TOKEN, body, {headers})
//.map(res => res.json())
.pipe(map((res: any) => {
if (res.access_token) {
return res.access_token;
}
return null;
}));
}
}
I know how to use .pipe with a single .map function like the example below, but I am struggling with implementing pipe() when multiple .map functions are involved.
.pipe(map(data => {})).subscribe(result => {
console.log(result);
});