Good, I am new in this of angular 2 and ionic 2 and I do not understand well the theory of the constructors and some things.
I have the following code:
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();
});
}
}
and I can not get this part to work:
var url = 'https://apibioidcrear.azurewebsites.net/Usuario/GetUsuario/2';
var response = this.http.get(url).map(res => res.json());
console.log(response);
I can not make myself recognize the http