Hi dear frineds i have a problem with ionic 2 CORS. I am getting this error.
my ionic.config.json
{
“name”: “weatherapp”,
“app_id”: “”,
“v2”: true,
“typescript”: true,
“proxies”: [
{
“path”: “/api”,
“proxyUrl”: “http://api.wunderground.com/api”
},
{
“path”:"/search",
“proxyUrl”: “http://autocomplete.wunderground.com”
}
]
}
my weather.service.ts
import {Injectable, Inject} from ‘@angular/core’;
import {Http} from ‘@angular/http’;
import {Observable} from ‘rxjs/Observable’;
import ‘rxjs/Rx’;
@Injectable()
export class WeatherService {
http: any;
searchUrl: any;
apiKey: string;
conditionsUrl: string;
static get parameters(){
return [Http];
}
constructor(http){
this.http = http;
console.log('Service Connected : )');
this.apiKey = '1e4420a89011eef4';
this.conditionsUrl= 'http://api.wunderground.com/api/'+this.apiKey+'/conditions/q';
this.searchUrl='http://localhost:8100/search/aq?query=';
}
getWeather(city, state){
return this.http.get(this.conditionsUrl+'/'+state+'/'+city+'.json')
.map(res => res.json());
}
searchCities(searchStr){
return this.http.get(this.searchUrl+''+searchStr)
.map(res => res.json());
}
}
my weather.ts
import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import { OnInit } from ‘@angular/core’;
import { WeatherService } from ‘…/…/services/weather.service’;
@Component({
selector: 'page-weather',
templateUrl: 'weather.html',
providers: [WeatherService]
})
export class WeatherPage {
results: any;
searchStr: any;
weather: any;
state: string;
city: string;
weatherService : WeatherService;
static get parameters(){
return [[WeatherService]];
}
constructor(weatherService) {
this.weatherService = weatherService;
this.city = 'Istanbul';
this.state = '';
this.searchStr;
this.weather;
this.results;
}
ngOnInit(){
this.weatherService.getWeather(this.city, this.state)
.subscribe(weather => {
//console.log(weather);,
this.weather = weather.current_observation;
})
}
getQuery(){
this.weatherService.searchCities(this.searchStr)
.subscribe(res => {
//console.log(weather);
this.results = res.RESULTS
console.log(this.results);
})
}
}
and my weather.html
I could not find my fault where it is. I want your help. Thanks in advance.