私はdetails.ts
ファイルの機能でgoogle Apiからデータを取得しています。 type-api.service.ts
ファイル内のdisplaingの活字体エラーProperty 'then' does not exist on type 'void'
プロパティ 'then'はionic2の型 'void'に存在しません
this.typeApi.getTypeDetails(baseUrl).then(data => {
});
、私は仕事に、このためにpackage.jsonファイルで
import { Injectable } from '@angular/core';
import { Http /*, Response*/ } from '@angular/http';
import 'rxjs/Rx';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class TypeApi {
constructor(public http: Http) {}
getTypeDetails(PlaceUrl){
this.http
.get(PlaceUrl)
.map(res => res.json())
.subscribe(
(data) => data,
(err) => err); // Reach here if fails
}
}
、
"dependencies": {
"@angular/common": "2.4.8",
"@angular/compiler": "2.4.8",
"@angular/compiler-cli": "2.4.8",
"@angular/core": "2.4.8",
"@angular/forms": "2.4.8",
"@angular/http": "2.4.8",
"@angular/platform-browser": "2.4.8",
"@angular/platform-browser-dynamic": "2.4.8",
"@angular/platform-server": "2.4.8",
"@ionic-native/core": "3.1.0",
"@ionic-native/geolocation": "^3.4.4",
"@ionic-native/launch-navigator": "^3.4.4",
"@ionic-native/splash-screen": "3.1.0",
"@ionic-native/status-bar": "3.1.0",
"@ionic/storage": "2.0.0",
"font-awesome": "^4.7.0",
"ionic-angular": "2.3.0",
"ionic2-rating": "^1.2.0",
"ionicons": "3.0.0",
"rxjs": "5.0.1",
"sw-toolbox": "3.4.0",
"zone.js": "0.7.2"
},
"devDependencies": {
"@ionic/app-scripts": "1.1.4",
"typescript": "2.0.9"
},
'プロパティ' subscribe 'がタイプ' Promise <{}> 'に存在しません。' Typescriptエラー。 –
'toPromise()'を使うと、質問のコードのように 'then'を使う必要があります。 'toPromise()'を使わなければ、私の答えの2番目の例のように 'subscribe()'を使うことができます。どういうわけか、これら2つのアプローチを混在させているようです。 –
私は 'toPromise()'を使用しませんでしたが、それでも 'Property 'subscribe'がタイプ 'Promise <{}>' Typescriptエラーに存在しませんでした。 –