AngularJS 不评估括号内的数据
AngularJS not evaluating data inside brackets
我在使用 AngularJs 时遇到了一个相当奇怪的问题。
我有一个 AngularJS(以后称为 AJS)应用程序正在侦听某些 SignalR 集线器。
当 SignalR 集线器收到一条消息(并且数据对象也在该调用中传递)时,它会在 AJS 中触发一个事件,该事件又会在 UI.
上显示一个 Toastr
现在我有大约 5 种不同类型的 SignalR 集线器,它们在 UI 上启动不同的 Toast。
我添加了另一个 Toast(根据新要求),它由另一个 SignalR 集线器启动。
问题:
当 SignalR 集线器收到一条消息时,我实现的这个新 toast 确实会显示,但不会呈现数据。我的意思是吐司出现时带有 {{ }} 这些括号。
除了新的以外,其他的 toasts 都遵循相同的程序并且表现得很好。
最奇怪的部分是我有另一个 AJS 方法 运行 以大约 30 秒的间隔从数据库中获取一些计数值(在后台使用 WEB API)。当此操作完成时,{{ }} 消失并且值显示得很好(我通过将鼠标光标悬停在烤面包机上来保持烤面包机处于活动状态,否则它会消失)。
//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 没有为烤面包机评估 html。但是问题是如何以及在哪里是我所反对的!!
请帮忙
对不起大家!!
我在 SignalR 端代码中犯了我的愚蠢错误,导致上述代码无法正常工作。
基本上,当我广播从 SignalR 收到的消息时,我忘记在根范围应用中包含广播行。
$rootScope.$apply(function () {
//broadcast event here
});
并且由于我没有编写根作用域应用程序,AJS 无法 运行 摘要循环,因此正在等待我或其他一些方法来启动摘要循环并评估 UI.
吸取教训。
谢谢:)
我在使用 AngularJs 时遇到了一个相当奇怪的问题。 我有一个 AngularJS(以后称为 AJS)应用程序正在侦听某些 SignalR 集线器。 当 SignalR 集线器收到一条消息(并且数据对象也在该调用中传递)时,它会在 AJS 中触发一个事件,该事件又会在 UI.
上显示一个 Toastr现在我有大约 5 种不同类型的 SignalR 集线器,它们在 UI 上启动不同的 Toast。
我添加了另一个 Toast(根据新要求),它由另一个 SignalR 集线器启动。
问题: 当 SignalR 集线器收到一条消息时,我实现的这个新 toast 确实会显示,但不会呈现数据。我的意思是吐司出现时带有 {{ }} 这些括号。
除了新的以外,其他的 toasts 都遵循相同的程序并且表现得很好。
最奇怪的部分是我有另一个 AJS 方法 运行 以大约 30 秒的间隔从数据库中获取一些计数值(在后台使用 WEB API)。当此操作完成时,{{ }} 消失并且值显示得很好(我通过将鼠标光标悬停在烤面包机上来保持烤面包机处于活动状态,否则它会消失)。
//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 没有为烤面包机评估 html。但是问题是如何以及在哪里是我所反对的!!
请帮忙
对不起大家!!
我在 SignalR 端代码中犯了我的愚蠢错误,导致上述代码无法正常工作。
基本上,当我广播从 SignalR 收到的消息时,我忘记在根范围应用中包含广播行。
$rootScope.$apply(function () {
//broadcast event here
});
并且由于我没有编写根作用域应用程序,AJS 无法 运行 摘要循环,因此正在等待我或其他一些方法来启动摘要循环并评估 UI.
吸取教训。 谢谢:)