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.
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
Post a Comment