"I am looking for a way to receive a response from a loopback in Angular7

Currently, I am utilizing angular7 with loopback. While I can successfully retrieve data, I am unsure how to receive error messages and response statuses. It would be helpful for me to understand what my response code is at the time of the request.

Output of Data

[
 {
"name": "karthik",
"lastname": "Selvakumar",
"course": "BE",
"year": "IV",
"id": 2
 }
]

Answer №1

To retrieve the response code from the HttpResponse, you can use the following code snippet:

import { Component, OnInit } from '@angular/core';

import { HttpClient } from  "@angular/common/http";
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
  status;

  constructor(private http: HttpClient) {}


  ngOnInit() {
    this.http.get('https://jsonplaceholder.typicode.com/posts?page=0', {observe: 'response'})
    .toPromise().then((response) => {
      this.status = response.status;
    })
  }
}

Check out the working example on StackBlitz

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A step-by-step guide to customizing the Material UI Chips delete SVG icon to appear in white color through

Using a Material UI component, I added a custom class to my chip. Attached is a screenshot showing what I mean. Currently, I am attempting to change the color of the cross button to white. After inspecting the element, I discovered that it is an SVG ico ...

What is the best way to add items to arrays with matching titles?

I am currently working on a form that allows for the creation of duplicate sections. After submitting the form, it generates one large object. To better organize the data and make it compatible with my API, I am developing a filter function to group the du ...

The date field's rows mysteriously disappear from the grocery crud table

Being a newcomer to Grocery CRUD, I must say I am truly impressed by the efficiency of this library. A huge thank you to all the talented developers behind this project. I seem to be facing a minor issue with displaying the date field in my table. While i ...

When sending a NULL value to be saved in a MySQL database, it is incorrectly being stored as an empty string instead of DbNull

I'm facing a strange issue where, despite sending a proper NULL from my C# code, the column in my database (which has a JSON type and default null value) is storing null instead of DbNull. I am attempting to save data to a JSON column in my database. ...

Issue with ActivatedRoute being empty when called in a Service in Angular version 2.0.2

I am interested in utilizing ActivatedRoute in a service to retrieve route parameters, similar to how it can be done in a Component. However, I have encountered an issue where the ActivatedRoute object injected into the Service does not contain the expecte ...

Leveraging the power of Kendo UI for Angular, bind the click event of a kendoButton to a method associated with a variable within

I have a variable called "message" in my component that is of type "any" and contains a method named "actionnowrapper()". When I bind this method to a regular HTML button like so, everything works as expected. <button (click)="message.actionnowrapper( ...

Struggling to capture the error thrown by the subscribe method in Angular using RxJs

In following the most recent tutorial, I learned about using pipe, tap, and catchError to intercept the result. This is what I currently have: getStatus(): Observable<boolean> { return this.http.get<boolean>('/status').pipe( ...

What are the advantages of utilizing the HttpParams object for integrating query parameters into angular requests?

After exploring different ways to include query parameters in HTTP requests using Angular, I found two methods but struggled to determine which one would be the most suitable for my application. Option 1 involves appending the query parameters directly to ...

Leverage the power of zustand actions in your axios queries!

In my React application, I have implemented Zustand for creating a store: import { create } from 'zustand'; interface IAuth { username: string; isAuthentificated: boolean; updateAuth: (isAuth: boolean) => void; } export const useAuth = ...

The value of type 'X' cannot be assigned to type 'Y' or 'undefined'

In my code, there is a component that requires a prop with an enum value: export enum AType { some = "SOME", word = "WORD", } const MyComponent = (arg: AType) => {} When I try calling this component like so: <MyComponent ar ...

Transition your Sequelize migrations to TypeORM

I'm currently in the process of transitioning a Node.js application from vanilla JS to Nest.js. In our previous setup, we used Sequelize as our ORM, but now we've decided to switch to TypeORM for its improved type safety. While exploring the Type ...

Steps for displaying a 404 page on a server-side rendered dynamic route following a client-side page transition

I'm currently developing a next.js project using Contentful as the Content Management System. My goal is to display a 404 page for a server-side rendered dynamic route after a client-side page transition. When I directly request the page (by entering ...

Angular2 ngIf directive issue after initial button click

I have recently started using the Angular2 Framework, so please bear with me if I make any common mistakes. I have set up two forms in separate div tags: one for logging in and another for password reset. Below the login form, there is a link that, when cl ...

Switching between various conditions

Here is a sample of my component: import { Component, OnInit } from '@angular/core'; @Component({ selector: 'myApp-component', templateUrl: './myApp.component.html', styleUrls: ['./myApp.component.scss'] }) ex ...

Acquire elements and variables from another component using a dual @NgModule setup in Angular2

I am looking to retrieve the value of the element variable and _dataTable component from the datatable.component.ts file (specifically from the render() function) in order to create a new event for a new button using element.on. Alternatively, I could crea ...

Error in Angular 4: Unexpected 'undefined' provided instead of a stream

I encountered an issue while attempting to make a HTTP Post request. The error message I received is as follows: auth.service.ts?c694:156 Something went wrong requesting a new password, error message: You provided 'undefined' where a stream ...

What are the most effective applications for utilizing an Observable Data Service?

Within my application setup, I have integrated a data service at the core level. The majority of functions within my app involve actions taken on the data model, to which components react. My goal is for components to be able to subscribe to the data ser ...

Exclude mock files from webpack configuration in AngularClass/angular2-webpack-starter for production builds

I've encountered some obstacles while working with the AngularClass/angular2-webpack-starter framework, specifically in configuring its webpack settings. My goal is straightforward, yet I've been struggling to achieve it. In my project directory ...

The HTML component fails to acknowledge width settings

I seem to be having trouble identifying an issue or perhaps I am misunderstanding something (I am using daisyui + nx + tailwind css + angular). To simplify my problem, let's consider the following scenarios: In the first scenario, I have: <div cl ...

Customizing styles for specific days on the mat-calendar component

Does anyone have suggestions on how to add a custom class to specific dates in an array? I want to highlight certain events. Here is the HTML code: <mat-card-content> <div class="date-picker"> <mat-calendar [selected]="selectedDates" ( ...