2016-12-21 8 views
0

Ich versuche, die HTTP-Methode zu erhalten Anfrage und ich habe einige Probleme, die Antwort zu abonnieren. hier ist mein Service:http erhalten Anfrage Fehler auf eckig2

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()); 
}} 

hier ist meine Komponente, wo im "GET" -Anfrage zu bekommen versuchen.

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) 
); }} 

meine IDE ist ATOM auf Fenster, und das ist das Problem, das es geben: Property 'subscribe' nicht auf Typ existiert 'String'.

Antwort

0

sollte es beobachtbar sein.

get_heb_date():Observable<string> // http return Observable<the_result_type> 
+0

nicht bekomme ich diesen Fehler: – user7326641

+0

Namen finden kann nicht beobachtbare – user7326641

+0

i Import hinzugefügt {beobachtbare} von ‚rxjs/Rx – user7326641

0

Das Problem war in den main.ts

platformBrowserDynamic().bootstrapModule(AppModule); 

der Name des Moduls wurde nicht eingerichtet. Jetzt funktioniert es. Danke.