2017-04-17 18 views

答えて

1

$ rootScope。$ apply();変更を反映するには が必要です。通知数を反映するために使用されるrootScope変数。

$ionicPlatform.ready(function() { 

    FCMPlugin.getToken(function(token) { 
     console.log('Device Token : ' + token); 
     DataSharingService.setItem('deviceToken', token); 
    }); 

    //FCMPlugin.onNotification(onNotificationCallback(data), successCallback(msg), errorCallback(err)) 
    //Here you define your application behaviour based on the notification data. 
    FCMPlugin.onNotification(function(data) { 

     console.log('Recived data : ' + JSON.stringify(data)); 
     **$rootScope.notificationCountValue = $rootScope.notificationCountValue + 1;** 
     $rootScope.notificationArray.push(data); 
     DataSharingService.setItem('notificationData', $rootScope.notificationArray); 
     **$rootScope.$apply();** 

     if (data.wasTapped) { 
      //Notification was received on device tray and tapped by the user. 
      console.log(JSON.stringify(data)); 
      App.go('notifications', { obj: data }); 

     } else { 
      //Notification was received in foreground. Maybe the user needs to be notified. 
      console.log(JSON.stringify(data)); 
     } 
    }); 


    }); 
関連する問題