Good problem with sending and fetching data with angle2
Auth.ts
import {Observable} from 'rxjs/Observable';
import {Injectable} from "angular2/core";
import {Http, Response} from "angular2/http";
if (!localStorage.getItem('token')) {
localStorage.setItem('token', 'false');
}
function fdsfds() {
if (localStorage.getItem('token') == 'true') {
return true;
}else{
return false;
}
}
@Injectable()
export class Auth {
loggedIn: any;
result: Object;
constructor(http:Http) {
this.loggedIn = fdsfds();
this.result = {friends:[]};
http.get('oii.json').map((res: Response) => res.json()).subscribe(res => this.result = res);
}
login() {
localStorage.setItem('token', 'true');
this.loggedIn = fdsfds();
}
logout() {
localStorage.setItem('token', 'false');
this.loggedIn = fdsfds();
}
check() {
return Observable.of(this.loggedIn);
}
}