Duplicate identifier 'http'


#1

Error
Close
Typescript Error
Duplicate identifier ‘http’.
D:/loadlink/src/pages/fastagregister/fastagregister.ts
constructor(public navCtrl: NavController, public navParams: NavParams, public http: HttpClient, private storage: Storage) {
Typescript Error
Subsequent variable declarations must have the same type. Variable ‘http’ must be of type ‘any’, but here has type ‘HttpClient’.
D:/loadlink/src/pages/fastagregister/fastagregister.ts
constructor(public navCtrl: NavController, public navParams: NavParams, public http: HttpClient, private storage: Storage) {
Ionic Framework: 3.9.2
Ionic App Scripts: 3.1.8
Angular Core: 5.2.9
Angular Compiler CLI: 5.2.9
Node: 8.11.0
OS Platform: Windows 7
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

fastagregister.ts

import { Component } from ‘@angular/core’;
import { IonicPage, NavController, NavParams } from ‘ionic-angular’;
import { InvoicePage } from ‘…/invoice/invoice’;
import { HttpClient, HttpHeaders } from ‘@angular/common/http’;
import { Storage } from ‘@ionic/storage’;

/**

@IonicPage()
@Component({
selector: ‘page-fastagregister’,
templateUrl: ‘fastagregister.html’,
})
export class FastagregisterPage {
public vehtype: any;
public o1: any;
public o2: any;
public o3: any;
public o4: any;
public o5: any;
public o6: any;
public o7: any;
public o8:any;
public o9:any;
public o10:any;
public add: any;
public dl: any;
public myDate: any;
public http:any;
public name:any;
public test:any;

constructor(public navCtrl: NavController, public navParams: NavParams, public http: HttpClient, private storage: Storage) {

this.storage.get('userId').then((value) => {
console.log('Testvalue is', value);
this.test = value;

});
}

ionViewDidLoad() {
console.log(‘ionViewDidLoad FastagregisterPage’);
}
register() {

let headers = new HttpHeaders();
headers.append("Content-Type", "application/json");

let body = {
action:“fastag_register”,
vehicle_type: this.vehtype,
address:this.add,
dob:this.myDate,
license_no:this.dl,

  id :this.test,
  image :'',
  rc_no:this.o1+ this.o2 + this.o3 + this.o4 + this.o5 + this.o6 + this.o7 + this.o8 + this.o9 + this.o10,
  rc:'',
  rc1:''
  
};

console.log(JSON.stringify(body));
this.http.post(‘http://freshkhata.com/fastag_api.php’, JSON.stringify(body), {headers: headers})

  .subscribe(data => {
  console.log(data);
  if(data['status']=='201')
  {
	  
	this.navCtrl.push(InvoicePage);  
  }
  else{
	  alert("RC Alerady exit");
  }
  });

}

next(el) {
el.setFocus();
}
navsdhfcfdbbfbf()
{
this.navCtrl.push(InvoicePage);
}
}


#2

you declared twice “http”, once as a string, another as a HttpClient !


#3

sir plz tell which line i have to del


#4

Never . You have to work to improve!


#5

ok anyway thanks a lot


#6

@bewithjatin Just to make it more clear, you have one http declared as any (not string) and another as HttpClient.

Like @trollanfer said, you should be able to solve that by yourself (because that is a very easy problem, otherwise it will be very difficult to create a real app).


#7

Or post in the jobs section of this forum :wink:


#8

Ok thanks sir solved you save me