Front end Angular app sends a GET to a backend Node API server. While API successfully fulfills this GET, its response res.status(200).send(data);
not triggers the breakpoint at NG caller, but Chrome F12 network tab shows there are data returned.
---- NG front-end component .ts:
import { Component, NgModule, OnInit } from '@angular/core';
import { mySvc } from '../mySvc.service';
import { record } from '../models/record';
export class ListAllRecordsComponent implements OnInit {
private allRecords: record[] = [];
constructor(private mySvc: mySvc) {}
...
public getAllRecords()
{
this.mySvc.getAllRecords().subscribe(response => this.allRecords = response, );
}
}
---- NG mySvc.service.ts
import { record } from '../models/record';
@Injectable()
export class mySvc {
constructor(private http: HttpClient) { }
const url = 'http://localhost:3000/somewhere';
getAllRecords(): Observable<record[]>
{
return this.http.get(url)
.pipe(
map((data: any) => data.record), // ??? break point is not triggered as expected when API sends back 200.
catchError( error => { return throwError('bad')})
)
}
---- Node API server controller:
exports.pgGetAll = (req, res) =>
{
objPS.pgGetAll( (err, data) =>
{
if (err)
res.status(500).send(err.message);
else
{
res.status(200).send(data); // break point shows data has all records
}
});
}
---- objPS:
const pgGetAll = (cbFunc) =>
{
pool.query('select * from "schema1"."table1"')
.then
(
good =>
{
cbFunc(null, good) // break point shows good has all records
},
bad =>
{
cbFunc(bad)
}
);
}