-1

我正面临 AngularJs 的一个相当奇怪的问题。我有一个 AngularJS(此后称为 AJS)应用程序,它正在监听某些 SignalR 集线器。当 SignalR 集线器接收到消息(并且数据对象也在该调用中传递)时,它会在 AJS 中触发一个事件,该事件反过来会在 UI 上显示一个 Toastr。

现在我有大约 5 种不同类型的 SignalR 集线器,它们在 UI 上启动不同的 Toast。

我添加了另一个由另一个 SignalR 集线器启动的 Toast(根据新要求)。

问题:当 SignalR 集线器收到消息但未呈现数据时,我实现的这个新 toast 确实出现了。我的意思是吐司出现在 {{ }} 这些括号中。

其他祝酒词都遵循相同的程序并且显示得很好,除了新的祝酒词。

最奇怪的部分是我有另一个 AJS 方法以大约 30 秒的间隔运行,它从数据库中获取一些计数值(在后台使用 WEB API)。当这个动作完成时 {{ }} 消失并且值显示得很好(我通过将鼠标光标保持在它上面来保持 toastr 活着,否则它会消失)。

    //SignalR hub initiates the following method
    $scope.$on("on_remote_event", function (argEvent, argData) {
        var toastrHtml = "<div class='my-toast-style'><div class='myLabel'>Client : {{ argData.ClientName }}</div><div class='myLabel'>Order Date: {{ argData.OrderedOn | date:'MM/dd/yyyy hh:mm a' }} EST</div></div>";
        generateAlertToast(toastrHtml, "Order Info", argData);
    });


    //this method will generate the toast as per the information passed to it
    function generateAlertToast(toastrHtml, toastrTitle, argData) {
        toastr.options = {
            "closeButton": true,
            "newestOnTop": true,
            "progressBar": true,
            "preventDuplicates": true,
            "timeOut": 60000,
            "positionClass": "toast-bottom-right"
        }

        var scope = $rootScope.$new();
        scope.argData = argData;
        //console.info(scope.argData);
        var compiledHtml = $compile(toastrHtml)(scope);
        toastr.info(compiledHtml, toastrTitle);
    };

现在我知道 AJS 没有评估 toastr 的 html。但是问题是如何以及在哪里是我正在努力解决的问题!

请帮忙。

4

1 回答 1

0

太对不起各位了!!

这是我在 SignalR 端代码中犯的愚蠢错误,因此上述代码不起作用。

基本上,当我广播从 SignalR 收到的消息时,我忘记在 rootscope 应用中包含广播行。

$rootScope.$apply(function () {
    //broadcast event here
});

由于我没有编写 rootscope 应用程序,AJS 无法运行摘要周期,因此正在等待我或其他方法来启动摘要周期并评估 UI 上的值。

学习到教训了。谢谢 :)

于 2015-09-24T14:45:22.633 回答