basher odeh
basher odeh

Reputation: 1

incorrect response in angular

i'm new at nodejs & angular here is my restAPI function :

  exports.getPlanningStages = async (req, res, next) => {
  const currentPage = req.query.page || 1;
  const perPage = 2;
  try {
    const totalItems = await Planningstage.find().countDocuments();
    const planningstages = await Planningstage.find()
      .populate('creator')
      .sort({ createdAt: -1 })
      .skip((currentPage - 1) * perPage)
      .limit(perPage);

    res.status(200).json({
      planningstages
    });
  } catch (err) {
    if (!err.statusCode) {
      err.statusCode = 500;
    }
    next(err);
   }
  };

at the console i see the correct response json array the angular code is

planningstage.service.ts

private ps: Planningstage[] = [];
  getPlanningStages() {
    return this.httpService
    .get<Planningstage[]>(
      "http://localhost:8080/planningstage/getPlanningStage"
    );
}

planningstage.component.ts

  ngOnInit() {
    this.fetch();
  }

  fetch() {
     this.psService.getPlanningStages().subscribe(resData => {
           console.log(resData);
     });

the response at the browser browser response

how can i read the currect response at my angular code

thank's

Upvotes: 0

Views: 39

Answers (1)

Sam
Sam

Reputation: 4284

It seems your problem is with this line,

res.status(200).json({
      planningstages
    });

instead of above line, make like this

res.status(200).json(planningstages);

Upvotes: 1

Related Questions