【发布时间】:2016-12-21 16:36:14
【问题描述】:
我正在尝试使用 http 方法获取请求,但我在订阅响应时遇到了一些问题。 这是我的服务:
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());
}}
这是我试图获取“GET”请求的组件。
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)
); }}
我的 IDE 是 Windows 上的 ATOM,这就是它指定的问题: 类型“字符串”上不存在属性“订阅”。
【问题讨论】:
标签: javascript angular typescript ionic2