json - ionic2 Property does not exist on type '{}' -


i getting json in typescript in ionic framework.
the json is:

{     "result": "success",     "user": {         "loggedin": true,         "name": "nulra",         "password": ""     } } 

and print data:

console.log("nulra checking: " + data.result + " " + data.user); 

it gives error:

typescript error  property 'result' not exist on type '{}'.  property 'user' not exist on type '{}'. 

auth-service.ts:

login(credentials) {     let opt: requestoptions;     let myheaders: headers = new headers;      myheaders.set('accept', 'application/json; charset=utf-8');     myheaders.append('content-type', 'application/json; charset=utf-8');     opt = new requestoptions({         headers: myheaders     })      return new promise((resolve, reject) => {         this.http.get(apiurl+'login/0/login?email='+credentials.email+'&password='+credentials.password, opt)         .map(res => res.json())         .subscribe(data => {             this.data = data;             resolve(this.data);         },(err) => {             reject(err);         });     }); } 

in login.ts:

dologin(){     this.authservice.login(this.logindata)     .then(data => {         console.log("nulra checking: " + data.result + " " + data.user);     }     .catch(err => {      }); } 

anyone know how deal it? because json confirmed have result , user. lot.

when console.log(data): enter image description here

try this-

public userdata: = {};  dologin(){     this.authservice.login(this.logindata)     .then(data => {         this.userdata = data;         console.log(`nulra checking: ${this.userdata.result} ${this.userdata.user}`);     }     .catch(err => {      }); } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -