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

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -