I am currently facing some challenges with subscribing to the response while using the http method get request. Below is my service implementation:
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/Rx';
import 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Injectable()
export class ProfileService{
http: any;
url: String;
date: Date;
constructor(http:Http){
this.http = http;
this.date = new Date();
//this.baseurl = 'www.google.com';
}
get_heb_date():String{
var year = this.date.getFullYear();
var month = this.date.getMonth();
var day = this.date.getDay();
//var after_sunset = 1;
//var convert_from_gregorian_to_hebrew = 1;
return this.http.get('http://www.hebcal.com/converter/?fg=json&gy='+year+'&gm='+month+'&gd='+day+'&g2h=1')
.map(res => res.json());
}}
Here is my component where I'm attempting to make the "GET" request.
import { Component } from '@angular/core';
import { JewristService } from '../../app/services/jewrist.service';
import { NavController } from 'ionic-angular';
import { ProfileService } from '../../app/services/profile.service';
import 'rxjs/Rx';
@Component({
selector: 'page-profile',
templateUrl: 'profile.html',
providers: [ProfileService]
})
export class ProfilePage {
username: String;
loggedin: Boolean;
date: String;
constructor(public navCtrl: NavController, private _httpservice: ProfileService) {
this.username = 'null';
}
ngOnInit(){
console.log('Profile component is running..');
this._httpservice.get_heb_date().subscribe(
data => this.date = JSON.stringify(data)
); }}
My IDE is ATOM on Windows, and it mentions the following problem: Property 'subscribe' does not exist on type 'String'.