How to consume a Json data by coming to an http address

Asked

Viewed 68 times

0

I’m trying to consume a Json data coming from an http address, but I don’t know what’s going wrong.

I divided the question into two groups my other doubt

   import { ComprasService } from './compras.service';

import { Compra } from './../compra/compra.model';

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



@Component({
  selector: 'tl-compras',
  templateUrl: './compras.component.html',
  styleUrls: ['./compras.component.css']
})
export class ComprasComponent implements OnInit {


events: Compra[];

  constructor(private comprasService: ComprasService) { }

  ngOnInit() {
    this.comprasService.events().subscribe(events => this.events = events);
  }
}

import { Injectable } from '@angular/core';

    import { PRODUC_API } from '../app.api';
    import {Http} from '@angular/http';
    import {Observable} from 'rxjs/observable';
    import { Compra } from '../compra/compra.model';
    import 'rxjs/add/operator/map';


    @Injectable()
    export class ComprasService {

        constructor(private http: Http) {}

        events(): Observable<Compra[]> {
            return this.http.get('${PRODUC_API}/events').map(response => response.json());
        }

    }
  • then I used in Ionic once follows link Created a proxy for connection https://github.com/leandroZanatta/mobWashMobile/blob/master/src/providers/proxy/proxy.ts using proxy https://github.com/leandroZanatta/mobWashMobile/blob/master/src/pages/cadastro/cadastro.ts Maybe Help

  • Do you have an error? Something appears in the console? Like this html?

  • See the devtools netowrk tab if the request is returning what you expect.

  • Which version of the angular you are using?

  • Good afternoon, use the browser tool to check if you have an error in the console. You can use this tool to press F12 from the browser ... If you have any mistakes, stick it here so we can take a look.

  • The error appears and this: :4200/$%7BPRODUC_API%7D/Events:1 Failed to load Resource: the server responded with a status of 404 (Not Found)

  • core.js:1673 ERROR Responseheaders: Headers {_headers: Map(8), _normalizedNames: Map(8)}ok: falsestatus: 404statusText: "Not Found"type: 2url: "http://localhost:4200/$%7BPRODUC_API%7D/Events"_body: "<! DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Cannot GET /$%7BPRODUC_API%7D/Events</pre> </body> </html>"proto: Body defaultErrorLogger @core.js:1673

Show 2 more comments
No answers

Browser other questions tagged

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