0

Buenas, soy nuevo en ésto de angular 2 e ionic 2 y no comprendo bien la teoria de los construcctores y algunas cosas.

Tengo el siguiente código:

import { Injectable } from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Http} from '@angular/http';
import 'rxjs/add/operator/map';
  


 
export class User {
  name: string;
  email: string;
 
  constructor(name: string, email: string) {
    this.name = name;
    this.email = email;
  }
}
 
@Injectable()
export class AuthService {
  currentUser: User;

  public login(credentials) {
    if (credentials.email === null || credentials.password === null) {
      return Observable.throw("Please insert credentials");
    } else {
      
 var url = 'https://apibioidcrear.azurewebsites.net/Usuario/GetUsuario/2';
 var response = this.http.get(url).map(res => res.json());
 console.log(response);

      return Observable.create(observer => {
        // At this point make a request to your backend to make a real check!
        let access = (credentials.password === "pass" && credentials.email === "email");
        this.currentUser = new User('Alexis Nichel', '[email protected]');
        observer.next(access);
        observer.complete();
      });
    }
  }
 
  public register(credentials) {
    if (credentials.email === null || credentials.password === null) {
      return Observable.throw("Please insert credentials");
    } else {
      // At this point store the credentials to your backend!
      return Observable.create(observer => {
        observer.next(true);
        observer.complete();
      });
    }
  }
 
  public getUserInfo() : User {
    return this.currentUser;
  }
 
  public logout() {
    return Observable.create(observer => {
      this.currentUser = null;
      observer.next(true);
      observer.complete();
    });
  }
}

y no logro que ésta parte funcione:

 var url = 'https://apibioidcrear.azurewebsites.net/Usuario/GetUsuario/2';
 var response = this.http.get(url).map(res => res.json());
 console.log(response);

No logro hacer que me reconozca el http

1 respuesta 1

1

En el constructor de tu clase donde defines constructor(name: string, email: string), deberías crear una variable http que haga referencia al tipo de dato Http que estás importando del Angular:

import {Http} from '@angular/http';

Quedaría de la siguiente forma:

constructor (name: string, email: string, http: Http)

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.