didinj / ionic2-rest-authentication

Ionic 2 REST API authentication
MIT License
19 stars 14 forks source link

Logout Error #1

Open ofaasd opened 7 years ago

ofaasd commented 7 years ago

i follow ur step by step tutorial in your site but i get this error after logout button clicked.

Uncaught (in promise): TypeError: _this.loading is undefined HomePage.prototype.logout/<@http://localhost:8100/build/main.js:56196:13 f</t.prototype.invoke@http://localhost:8100/build/polyfills.js:3:8969 onInvoke@http://localhost:8100/build/main.js:4480:28 f</t.prototype.invoke@http://localhost:8100/build/polyfills.js:3:8896 c</r.prototype.run@http://localhost:8100/build/polyfills.js:3:4121 f/<@http://localhost:8100/build/polyfills.js:3:13729 f</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:9644 onInvokeTask@http://localhost:8100/build/main.js:4471:28 f</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:9557 c</r.prototype.runTask@http://localhost:8100/build/polyfills.js:3:4812 o@http://localhost:8100/build/polyfills.js:3:1884 t/this.invoke@http://localhost:8100/build/polyfills.js:3:10673

auth-service.ts logout(){ return new Promise((resolve, reject) => { let headers = new Headers(); headers.append('X-Auth-Token', localStorage.getItem('token'));

   this.http.post(apiUrl+'user/logout', {}, {headers: headers})
     .subscribe(res => {
       localStorage.clear();
     }, (err) => {
       reject(err);
     });

}); }

home.ts logout() { this.AuthServiceProvider.logout().then((result) => { this.loading.dismiss(); let nav = this.app.getRootNav(); nav.setRoot(LoginPage); }, (err) => { this.loading.dismiss(); this.presentToast(err); }); }

can u help me to fix this ?

didinj commented 7 years ago

you are not declaring "loading" variable