0

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

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.