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);
});
});
})