Passing callback data

by shah77   Last Updated May 16, 2018 09:05 AM

how do I pass data from backend which is in loopback to frontend which is in angular 2 using callback function? I want to display the callback data in frontend but there are nothing passed to frontend.

Loopback

  Attendance.checkIn = function(data, options, cb) {
      app.models.attendance.find({where:{and:[{eventId:event.id}, 
      {userId:options.accessToken}]}}, function(err,findDuplicate){
      if(findDuplicate){   
           //pass this to frontend
           cb(null, "you have already checkin");
      }
      else{
         Attendance.create(data, function(err,Attendance){
           if(Attendance){
               //pass this to frontend
               cb(null, "inserted successfully!");
           }
           else{
               console.log("fail to insert data!");
           }
        });
      }
      }) 
   }

Angular

    var data = {   
      "token": '1234567'       
    }

   this.attendanceApi.checkIn(data).subscribe( 
      (datas:Attendance) => {

       //Display the callback data here
        return datas;

      },
      err =>{
        console.log(err.message);     
      }
    );


Related Questions




Architecture of Angular 5 application

Updated April 04, 2018 19:05 PM


Angular template variable reference

Updated December 19, 2017 02:05 AM