0

我正在尝试使用可用的教程重新创建启用 Web 套接字的应用程序

http://www.hivemq.com/build-javascript-mqtt-web-application/

有角度和引导。

这是我的示例代码:

client.onMessageArrived = function (message) {
    //Do something with the push message you received
    $log.info('Message arrived');

    //   $log.info(message.payloadString);

    $scope.tweet = message.payloadString;
    $log.info($scope.tweet);
};

这是我试图填充消息的文本框的 html 代码。

<input type="type" name="input" value="none" ng-model="tweet" />

问题是,在 Web 浏览器的控制台中,我可以看到 $log.info($scope.tweet)打印已发布的消息,但文本框没有被填充。为什么会发生这种情况?谢谢

这是控制器的完整代码

(function () { var HomeController = function ($scope, $log, $modal) {

    $scope.displayTick = false;

    var client = new Messaging.Client("broker.mqttdashboard.com", 8000, "myclientid_" + parseInt(Math.random() * 100, 10));

    client.onConnectionLost = function (responseObject) {

        $log.info('Connection Lost');
    };


    client.onMessageArrived = function (message) {

        $log.info('Message arrived');
        $log.info('msg:' + message.payloadString);

        $scope.tweet = message.payloadString;
        $log.info($scope.tweet);


    };


    var options = {
        timeout: 3,

        onSuccess: function ($scope) {

            $log.info('Connected to broker');

            client.subscribe('Event', { qos: 2 });

            $scope.displayTick = true;

            $log.info($scope.displayTick);
        },

        onFailure: function (message) {
            $log.info('Failed Connected to broker');
            alert("Connection failed: " + message.errorMessage);
        }
    };


    client.connect(options);
    client.subscribe('angular', { qos: 2 });

}; 

IotApp.controller("HomeController", HomeController);

}());

4

0 回答 0