How to Angular 7 handle http request

How to Angular 7 handle http request

I'm having problem getting a simple http call to work.

I'm having problem getting a simple http call to work.

I came from angularjs and AFAIK .then = .subscribe

So Here's my problem, Can I not use the .subscribe in my auth-service and instead use it in my login.component.ts and I want to get the Http Status also.


const httpOptions = {
   headers: new HttpHeaders({
       'Content-Type': 'application/json'

export class AuthService { constructor(private http: HttpClient) { } mainUrl = 'http://localhost:4000/api/v1'; signIn(user: User) { // this is working fine, BUT I want to use .subscribe in login component const url = ${this.mainUrl}/sign_in; return<any>(url, user, httpOptions) .subscribe( (data) => { console.log(data); // I want to get the 200 status not only the jwt token return data; }, (error) => console.log(error) ) } }


this.authService.signIn(userData); // how to use .subscribe here ? 


Here's what my angularjs code look like.


function signIn(data) {
        return $ + '/api/v1/sign_in_2', data)

    function success(response) {
        return response;

    function fail(e) {
        return e;


vm.doLogin = function (userData) {
  vm.spinner = true;
  elixirAuthServices.signIn(userData).then(function (data) {

if (data.status === 200 || data.status === 201) {
  elixirAuthServices.getUser().then(function (data) {
    vm.user_id =;
} else {
  vm.authenticateErr = true;
  vm.spinner = false;'Username or Password is incorrect');

}); };


Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Install Angular - Angular Environment Setup Process

Install Angular in easy step by step process. Firstly Install Node.js & npm, then Install Angular CLI, Create workspace and Deploy your App.

Basics of Angular: Part-1

What is Angular? What it does? How we implement it in a project? So, here are some basics of angular to let you learn more about angular. Angular is a Typesc

Angular Sass: How To Use Sass In Angular 9 Tutorial

Sass in Angular is an extension of CSS that allows you to use things like variables, nested rules, inline imports. Angular supports Sass, CSS, and Less.

How to Upgrade Angular 8 To Angular 9

Angular is currently the most popular JavaScript framework and is used by several expert developers when developing single-page applications or powerful web apps. It has become quite crucial for the developers of Angular to add more features to the framework and fix the bugs . Let's learn how to upgrade Angular 8 to Angular 9 using CLI.

Visualizing data with NGX-Charts in Angular

Data Science, Data Analytics, Big Data, these are the buzz words of today's world. A huge amount of data is being generated and analyzed every day. So communica