Ionic 3 Login Authentication Using API - Cannot read property 'json' of null

后端 未结 4 1257
情深已故
情深已故 2021-01-17 18:14

I am doing authentication in Ionic 3 using API but In the login process, it is showing error: Cannot read property \'json\' of null

This is my provi

4条回答
  •  抹茶落季
    2021-01-17 18:32

    Please change the method like this

    In your ts rest.api.ts File

    getUsers(credentials, type) {
        return new Promise((resolve, reject) => {
          var headers = new Headers();
          headers.append('Access-Control-Allow-Origin' , '*');
          headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
          headers.append('Accept','application/json');
          headers.append('content-type','application/json');
    
          this.http.post(apiUrl + type, JSON.stringify(credentials), {headers: headers})
            .subscribe(res => {
              resolve(res); ----- Change like this
            }, (err) => {
              reject(err);
            });
        });
      }
    

    in your loginpage.ts file

       getloginUsers(){
        this.restProvider.getUsers(this.userData,'user_Login').then((result) => {
        if(result){
         this.responseData = result.json();
         if(this.responseData.userData){
         console.log(this.responseData);
         console.log("User Details");
         this.navCtrl.push(ListPage);
         }
         else{
           console.log("Incorrect Details"); }
        }
         }
         , (err) => {
         // Error log
       });
    
     }
    

提交回复
热议问题