The first parameter for this.http.request("") should be the URL you are trying to get data from.
As you are trying to convert the response you receive to JSON - you need to provide an URL which can return JSON response. (https://xyz.firebaseio.com doesnât return a JSON response)
what is json placeholder, and the whole address i mean im unable to understand my data is at firebase how can i get data from another url like you said jsonplaceholder.typicode
@yoyodj As @sankar_gopalan mentioned, the first parameter should be a URL which returns JSON data. Letâs say that your Firebase URL is https://xyz.firebaseio.com, then you canât use just https://xyz.firebaseio.com because it doesnât return JSON - it returns HTML, which means that you have to specify that you want JSON data: https://xyz.firebaseio.com/.json. Now the returned data is in JSON format but it returns the whole content of the Firebase instance, which you probably donât want. Letâs say that you want to retrieve all posts which are stored in posts under the Firebase root, then your URL should be https://xyz.firebaseio.com/posts.json. Also donât forget to use a real Firebase URL, i.e. xyz should be the name of the Firebase instance that youâre trying to get data from, which means that you should replace it with the Firebase data URL of your Firebase account.
this.http.request('https://xyz.firebaseio.com/posts.json')
// Call map on the response observable to get the parsed object.
.map((res) => res.json())
// Subscribe to the observable to get the parsed object and use it.
.subscribe((posts) => {
console.log(posts);
this.list = posts;
}, (err) => {
console.log(err);
});
as response i got Object {-KF6dIZnUliIVtNykDEN: Object} at the console, also adding this line .map((res) => res.json()) giving me error .map is not defined,
how can i do this
Oh yes can i build facebook like application in this like if i create post(it will be object in the list with unique id) and when somebody comments it should make sure belong to that post(i think with unique id its possible, can i retrieve id)
Please look at my console.log at my user_service.js.
I can console.log email or objectId but fail for user-token.
My problem is how to get the user-token and save it to localstorage so i can use it for another purpose??
my user_service.js
import {Injectable} from 'angular2/core';
import {Http, Response} from 'angular2/http';
import {Headers, RequestOptions} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import {BackendService} from './backend_service';
import {Storage, LocalStorage, Events} from 'ionic-angular';
import 'rxjs/Rx';
@Injectable()
export class UserService {
static get parameters() {
return [[Http], [BackendService], [Events]];
}
constructor(http, backendService, events) {
this.http = http;
this.backendService = backendService;
this.events = events;
this.user = {};
this.storage = new Storage(LocalStorage);
this.HAS_LOGGED_IN = 'hasLoggedIn';
this.Backend_Login_Url = backendService.BackendLoginUrl
this.Backend_Register_Url = backendService.BackendRegisterUrl
this.Backend_Logout_Url = backendService.BackendLogoutUrl
this.Backend_Header = backendService.BackendHeader
}
userLogin(userData)
{
let body = JSON.stringify({ login: userData.email, password: userData.password });
let headers = new Headers(this.Backend_Header);
let options = new RequestOptions({ headers: headers });
return this.http.post(this.Backend_Login_Url, body, options)
.map((res) => {
let data = res.json();
console.log('data.email at user_service', data.email); // result : personal@gmail.com
console.log('data.objectId at user_service', data.objectId); // result C8FE36A2-9396-13C5-FF9C-8F8EF7F07900
console.log('data.user-token at user_service', data.user-token); // result Reference error : Token is not defined
this.storage.set('userStorage', JSON.stringify(data)); // result : success
return data;
});
}