Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Error: Can't resolve all parameters for HttpHeaders: (?)

$
0
0

@NorthFred wrote:

What am I doing wrong? My code as given below is trying to get response from a GET method. However, I am running into this error: Error: Can’t resolve all parameters for HttpHeaders: (?).

I have been struggling with this for 2 days, following the advice on StackOverflow, Ionic forum and others… But I can’t seem to figure out what I am missing…

Inside home.ts:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { HttpClient, HttpClientModule, HttpHeaders } from '@angular/common/http';
import 'rxjs/add/operator/map';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, private http: HttpClient, private headers: HttpHeaders) {

    this.headers = new HttpHeaders({ 'Content-Type': 'application/json'});
    this.headers.append('Access-Control-Allow-Origin', '*')
    this.headers.append("Access-Control-Allow-Headers","*");
    this.headers.append('Access-Control-Allow-Methods', 'GET');	
  
    this.httpGet('https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

  }
  httpGet(url) {
	  console.log("you are here");
    this.http.get(url, { headers: this.headers })
      .map(res => res)
      .subscribe(success => {
        alert("success");
      },
      error => {
        alert(error);
      },
      () => {
        alert("DONE!");
      }
    
    )
  }
}


Inside app.module.ts:


import { HttpClientModule, HttpHeaders } from '@angular/common/http';

import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';

import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';



@NgModule({
  declarations: [
    MyApp,
    AboutPage,
    ContactPage,
    HomePage,
    TabsPage
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    AboutPage,
    ContactPage,
    HomePage,
    TabsPage
  ],
  providers: [
    HttpHeaders,
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>