Beginner in Angular Problems with observable

Asked

Viewed 157 times

0

I’m new to the world of angular development and I’m having a simple problem but I can’t solve it.

I started the project using angular cli 1.5.2, where this using angular 5.0.0

I’m trying to perform a simple query to the api with path in http://localhost:3333/app/users/login, using Postman I can access it.

I put the observable in the page constructor, but the code is simply ignored, does not request or even show it on the browser network.

Follow the only files I changed when starting the application with angular cli to Sass.

Can you help me make this request ?

appComponent file

import { Component } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

export class AppComponent {
  title = 'app';

  constructor(private http:Http) {
    http.post('http://localhost:3333/app/users/login', { email: 'teste', password: 21323 })
    .map((response: Response) => {
        console.log('veio')
    });



  }

}

app module file.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import 'rxjs/add/operator/map';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  • Opa forgot to say more has no compile error of type script or webpack

1 answer

0

After researching further, and talking with some friends, I discovered that the request was not being answered correctly, when exchanging map for subscribe the request started working.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.