ng的问题显示angularjs



ng-show在angular js中对我来说不太好用。这就是";加载";div:

<div class="loader" ng-show="vm.loadingNotifications" ng-cloak>loading...</div>

这就是控制器中的API调用:

function getNotifications(userId) {
if (vm.generalNotifications.length > 0) {
vm.loadingNotifications = false;
} else {
vm.loadingNotifications = true;
$.ajax({
type: 'GET',
url: AppConfig.apiUrl + 'Notifications/GetAllNotificationsByUserId?userId=' + userId,
success: function (notifications) {
if (notifications) {
$("#all-not").addClass("active");
if (notifications.length > 0) {
let tempNotifications = [];
for (let j = 0; j < notifications.length; j++) {
let element = notifications[j];
let title = getSpecificConst(element.NotificationTitle)
element.NotificationTitle = title;
let text = getSpecificConst(element.NotificationText)
element.NotificationText = text;
tempNotifications.push(element);
}
vm.generalNotifications = sortArray(tempNotifications);
vm.displayedNotifications = sortArray(tempNotifications);
vm.isEmptyNotifications = false;
}
else {
vm.isEmptyNotifications = true;
}
} else {
vm.isEmptyNotifications = true;
}
vm.loadingNotifications = false;
}
});
}
}

虚拟机加载正在明显更新,但ng显示堆栈始终为true。

您需要在控制器上使用AngularJS Scope。


$scope.vm = {
generalNotifications:[],
loadingNotifications: false,
....
};
function getNotifications(userId) {
if ($scope.vm.generalNotifications.length > 0) {
$scope.vm.loadingNotifications = false;
} else {
$scope.vm.loadingNotifications = true;
.....
}

相关内容

  • 没有找到相关文章

最新更新