2
なしプロバイダ
イムionic2 rc.5にIONIC 2 - ヘッダ
を使用してこれは私のプロバイダである:
import {Http, Headers, RequestOptions} from '@angular/http';
import { Injectable, Component } from '@angular/core';
import { NavController, AlertController, LoadingController, Loading } from 'ionic-angular';
import {Observable} from 'rxjs/Observable';
import {Geolocation} from 'ionic-native';
import 'rxjs/add/operator/map';
@Injectable()
export class Setup {
loading: Loading;
constructor(public http: Http, public headers: Headers, private alertCtrl: AlertController, private loadingCtrl: LoadingController) {}
public generalSetupCheck() {
if (localStorage.getItem('guards') == null) {
console.log("CREATE GUARDS localStorage")
localStorage.setItem('guards', JSON.stringify([]))
}
if (localStorage.getItem('sms_list') == null) {
console.log("CREATE SMS_LIST localStorage")
localStorage.setItem('sms_list', JSON.stringify([]))
}
}
public getProfile (token) {
this.showLoading()
console.log("GET USER PROFILE")
this.headers.append('Authorization','Token ' + token);
this.http.get('http://30d2ef2d.ngrok.io/profile/', { headers: this.headers }).subscribe(data => {
console.log("USER PROFILE: success")
localStorage.setItem('user', JSON.stringify(data.json()));
this.getGPS()
}, error => {
console.log("error")
},() => {});
}
public getGPS() {
console.log("GET GPS LOCATION")
Geolocation.getCurrentPosition().then(pos => {
var coords = pos.coords.longitude +","+ pos.coords.latitude;
console.log('FOUND GPS LOCATION: lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude)
this.determinePA(coords)
});
}
public determinePA (coords) {
console.log("FINDING PROTECTED AREA")
this.http.get('http://30d2ef2d.ngrok.io/protected-area/list/' + coords + '/', { headers: this.headers }).subscribe(data => {
if (data.json().length > 0) {
console.log("FOUND PROTECTED AREA")
console.log(data.json().length)
} else {
console.log("PROTECTED AREA NOT FOUND")
}
}, error => {
console.log("error")
},() => {});
}
showLoading() {
this.loading = this.loadingCtrl.create({
content: 'Please wait...'
});
this.loading.present();
}
showError(text) {
setTimeout(() => {
this.loading.dismiss();
});
let alert = this.alertCtrl.create({
title: 'Authentication problem',
subTitle: text,
buttons: ['OK']
});
alert.present(prompt);
}
}
しかし、それは私のヘッダのために何プロバイダにエラーを与えない:
error_handler.js:47EXCEPTION: Error in ./MyApp class MyApp - inline template:0:0 caused by: No provider for Headers!
ErrorHandler.handleError @ error_handler.js:47
(anonymous) @ application_ref.js:210
t.invoke @ polyfills.js:3
onInvoke @ ng_zone.js:236
t.invoke @ polyfills.js:3
e.run @ polyfills.js:3
(anonymous) @ polyfills.js:3
t.invokeTask @ polyfills.js:3
onInvokeTask @ ng_zone.js:227
t.invokeTask @ polyfills.js:3
e.runTask @ polyfills.js:3
i @ polyfills.js:3
error_handler.js:49ORIGINAL EXCEPTION: No provider for Headers!
ErrorHandler.handleError @ error_handler.js:49
(anonymous) @ application_ref.js:210
t.invoke @ polyfills.js:3
onInvoke @ ng_zone.js:236
t.invoke @ polyfills.js:3
e.run @ polyfills.js:3
(anonymous) @ polyfills.js:3
t.invokeTask @ polyfills.js:3
onInvokeTask @ ng_zone.js:227
t.invokeTask @ polyfills.js:3
e.runTask @ polyfills.js:3
i @ polyfills.js:3
error_handler.js:52ORIGINAL STACKTRACE:
ErrorHandler.handleError @ error_handler.js:52
(anonymous) @ application_ref.js:210
t.invoke @ polyfills.js:3
onInvoke @ ng_zone.js:236
t.invoke @ polyfills.js:3
e.run @ polyfills.js:3
(anonymous) @ polyfills.js:3
t.invokeTask @ polyfills.js:3
onInvokeTask @ ng_zone.js:227
t.invokeTask @ polyfills.js:3
e.runTask @ polyfills.js:3
i @ polyfills.js:3
error_handler.js:53Error: No provider for Headers!
at NoProviderError.BaseError [as constructor] (errors.js:24)
at NoProviderError.AbstractProviderError [as constructor] (reflective_errors.js:41)
at new NoProviderError (reflective_errors.js:72)
at ReflectiveInjector_._throwOrNull (reflective_injector.js:758)
at ReflectiveInjector_._getByKeyDefault (reflective_injector.js:786)
at ReflectiveInjector_._getByKey (reflective_injector.js:749)
at ReflectiveInjector_.get (reflective_injector.js:558)
at AppModuleInjector.get (module.ngfactory.js:270)
at AppModuleInjector.getInternal (module.ngfactory.js:379)
at AppModuleInjector.NgModuleInjector.get (ng_module_factory.js:94)
プロパティとしてそれらを使用することができます'ヘッダ'はタイプ 'セットアップ'には存在しません。それはgetProfile fuctionのthis.headers = ...だと思います。そしてそれは同じことを言います:NavControllerのためのプロバイダはありません! – Harry
私の答えが更新されました。 NavControllerをどこで定義するかわかりません。 – PierreDuc
ありがとう、私は何かを学んだ!私はイオン2を嫌いです:-( – Harry