Property 'mobile' does not exist on type 'ContactPage'


#1

contact.ts
import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import { SelectPage } from ‘…/select/select’;
import { HttpClient, HttpHeaders } from ‘@angular/common/http’;
@Component({
selector: ‘page-contact’,
templateUrl: ‘contact.html’
})
export class ContactPage {

constructor(public navCtrl: NavController, public http: HttpClient ) {

}
ionViewDidLoad() {
console.log(‘ionViewDidLoad SelectPage’);

}
navsdhfc()
{
this.navCtrl.push(SelectPage);
}
register() {
let headers = new Headers();
headers.append(“Content-Type”, “application/json”);
var mobile11=this.mobile;
if(mobile11.length == 10)
{
let body = {
action:“common_register”,
mobile: this.mobile,
city: this.city,
name:this.name
};

this.http.post('http://freshkhata.com/fastag_api.php', JSON.stringify(body), {headers: headers})
  
  .subscribe(data => {
 
  if(data.status=='201')
  {
	   console.log(data);
	this.navCtrl.push(SelectPage);  
  }
  else{
	  alert("User Alerady exit");
  }
  });

}
else
{
alert(“Invalid Mobile Number”);
}
}
}

contact.html

<ion-col>
<ion-item>
 <ion-label floating class="lab">Mobile Number</ion-label>
 <ion-input type="number" class="text" maxlength="10" [(ngModel)]="mobile"></ion-input>
Name City
<ion-col class="footb" (click)="register()">

Register

Errors

Property ‘mobile’ does not exist on type ‘ContactPage’.
D:/loadlink/src/pages/contact/contact.ts
action:“common_register”,
mobile: this.mobile,
city: this.city,
Typescript Error
Property ‘city’ does not exist on type ‘ContactPage’.
D:/loadlink/src/pages/contact/contact.ts
mobile: this.mobile,
city: this.city,
name:this.name
Typescript Error
Property ‘name’ does not exist on type ‘ContactPage’.
D:/loadlink/src/pages/contact/contact.ts
city: this.city,
name:this.name
};


#2

@bewithjatin It seems the error is exactly what it shows: Property ‘mobile’ does not exist on type ‘ContactPage’.

You use the mobile property here:

let body = {
action:“common_register”,
mobile: this.mobile,
city: this.city,
name:this.name
};

Look that you reference this.mobile, but there is no mobile property. You also have [(ngModel)]="mobile", that expects a mobile property that isn’t in your class (although it shouldn’t give you a error, the error is the first case).

Solution:

Just create the property:

export class ContactPage {
    
    public mobile: any;

    constructor(....

You probably will receive similar errors with city and name.


#3

Thanks A lot save me