Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228603

Help me for data binding

$
0
0

I changed the code as you suggested.
But not working and console said ..

Uncaught TypeError: $scope.apply is not a function

.controller('MqttCtrl', function($scope, $stateParams) {

  $scope.data = {
    'mqttTopic' : '',
    'mqttMessage':''
  };


  var mqtt = require('mqtt');
  var client=mqtt.connect('ws://172.16.100.103:3333');

  client.on('connect', function(){

    client.subscribe('ionic/logan');

    client.on('message', function(topic, message) {
      var parsed=JSON.parse(message);

     $scope.data.mqttTopic=topic;
     //$scope.data.mqttMessage=parsed;

     $scope.apply(function(){

        $scope.data.mqttMessage=parsed;     //

    });

     console.log($scope.data.mqttTopic);
     console.log($scope.data.mqttMessage);
    });

  });


})

Viewing all articles
Browse latest Browse all 228603

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>