martes, 6 de junio de 2017

Errores en Angular 2+


Error en consola al desinstalar/actualizar Angular-CLI


npm ERR! cb() never called!  npm ERR! This is an error with npm itself. Please report this error at: npm ERR!       npm ERR! A complete log of this run can be found in: npm ERR!     C:\Users\[user]\AppData\Roaming\npm-cache\_logs\2017-06-08T23_59_09_192Z -debug.log
Solución: instalar, desinstalar y volver a instalar globalmente el Angular-CLI.
https://github.com/npm/npm/issues/16738#issuecomment-306415522
https://github.com/angular/angular-cli/issues/5558
https://codecanyon.net/item/serverless-angular-2-bootstrap-4-web-app-template-with-membership/19304446/comments?page=1&filter=all#comment_16411362
https://github.com/angular/angular-cli#updating-angular-cli

Error al mapear data usando la clase http

import { Injectable } from '@angular/core';
import {Http, Response} from "@angular/http";
import {Quote} from "../quote";
import {Constants} from "../constants";


@Injectable()
export class QuotesServiceService {

  API:string;
  constructor(private http: Http, private con:Constants) {
    this.API=this.con.API_URL+'quotes/';
  }

  getQuotes():Observable{

    return this.http.get(this.API)
        .map(
            (response : Response)=>{
              return response.json().quotes;
            }
    );
  }

}
Property 'map' does not exist on type 'Observable<response>'
Solución: Importar Observable y map desde rxjs.
import {Observable} from "rxjs";
//import 'rxjs/Rx'
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/go';
https://stackoverflow.com/questions/36947748/angular-2-beta-17-property-map-does-not-exist-on-type-observableresponse
https://stackoverflow.com/questions/37030963/angular-2-2-0-0-rc-1-property-map-does-not-exist-on-type-observableresponse
https://stackoverflow.com/questions/34515173/angular-2-http-get-with-typescript-error-http-get-map-is-not-a-function-in


Error al acceder a un servidor con Cors en localhost

XMLHttpRequest cannot load localhost:{port}/api/{query}. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
Solución: agregar http:// al localhost en la llamada al API, quedando http://localhost:{port}/api/{query}
https://www.youtube.com/watch?v=84bXch-YIvI&lc=z13yd5ow5xfhwrl5z04ccvabskvfvdnxclo0k.1496769397077381

Néstor Mercedes

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 comentarios:

Publicar un comentario