Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果没有可用的应用程序,则显示消息_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 如果没有可用的应用程序,则显示消息

Javascript 如果没有可用的应用程序,则显示消息,javascript,html,angularjs,Javascript,Html,Angularjs,我想显示一条消息,上面写着“没有可用的通知”。如果页面上不包含任何应用程序,我希望显示此内容。因此,如果页面为黑色,则应显示消息。我目前已经在HTML中设置了消息,但它只是没有正确显示 控制器 $scope.dismissNotifications = function(app, ev) { var confirm = $mdDialog.confirm() .title('Confirm Dismiss All') .content('Are you sure you wa

我想显示一条消息,上面写着“没有可用的通知”。如果页面上不包含任何应用程序,我希望显示此内容。因此,如果页面为黑色,则应显示消息。我目前已经在HTML中设置了消息,但它只是没有正确显示

控制器

$scope.dismissNotifications = function(app, ev) {
  var confirm = $mdDialog.confirm()
    .title('Confirm Dismiss All')
    .content('Are you sure you want to dismiss notifications?')
    .ariaLabel('Confirm Dismiss All')
    .ok('Confirm')
    .cancel('Cancel')
    .targetEvent(ev);

  $mdDialog.show(confirm).then(function() {
    var notifications = app.notifications;
    for (var id in notifications) {
      Service.dismissNotification(notifications[id].id).then(function(notificationId) {
        return function (response) {
          delete app.notifications[notificationId];
        }
      });
    }
  }, function() {
    return false;
  });
};

$scope.init = function () {
  Service.getUserAppsByEmail(SecService.secState.username).then(function (response) {
    var apps = response.applications;
    $scope.appList['alerts'] = {
      name: 'Alerts',
      notifications: {}
    } ;
    for(var i = 0; i < apps.length; i++) {
      $scope.appList[apps[i].appId] = {
        name: apps[i].name,
        icon: apps[i].icon,
        notifications: {}
      }
    }
angular.module('notifications').filter('NotificationsExistFilter', function () {
return function (apps) {
if (!apps) {
  return false;
}

var retVal = false;
angular.forEach(apps, function (app, index) {
  if (!retVal) {
    angular.forEach(app.notifications, function (value, index) {
      if (!retVal) {
        retVal = true;
      }
    })
  }
});

return retVal;
};
$scope.dismissNotifications=函数(应用程序,ev){
var confirm=$mdDialog.confirm()
.title('确认全部驳回')
.content('确实要取消通知吗?')
.ariaLabel('确认全部驳回')
.ok('确认')
.cancel('cancel')
.目标事件(ev);
$mdDialog.show(confirm).then(function(){
var通知=app.notifications;
for(通知中的变量id){
Service.dismissNotification(通知[id].id)。然后(函数(notificationId){
返回函数(响应){
删除应用程序通知[notificationId];
}
});
}
},函数(){
返回false;
});
};
$scope.init=函数(){
Service.getUserAppsByMail(SecService.secState.username)。然后(函数(响应){
var apps=response.applications;
$scope.appList['alerts']={
名称:“警报”,
通知:{}
} ;
对于(变量i=0;i
HTML


没有可用的通知

{{app.name}

{{{notification.message}-


您可以在脚本中使用ng hide标记来推动div运行。 下面是一个

  • 中,此处无任何内容!

    布尔隐藏true/false由列表中的项目数设置。在您的情况下,如果将此
    添加到html(或其他div或任何您想要的内容)中,并设置
    ng hide=“appList.length”
    ,您将得到想要的结果。

    //在html中,在ng之外重复

    <div ng-show = "appListEmpty" class="m2" style="color: #FFFFFF; padding: 24px 36px;"  (INCLUDE A FILTER OR SORTS HERE)>No Notifications or Alerts Available<div>
    
    没有可用的通知或警报
    
    //在控制器中(将if语句放在init函数中)

    $scope.appListEmpty=false;
    如果(应用列表长度<1){
    $scope.appListEmpty=true;
    

    }

    这将修复我试图完成的任务。在这种情况下,添加筛选器是最简单的修复方法

    将此添加到HTML中

    <div class="m2" style="color: #FFFFFF; padding: 24px 36px;" ng-if="!(appList | NotificationsExistFilter)">No Notifications or Alerts Available</div>
    

    这对我也不起作用。我添加了一些代码来使用筛选器,但现在无论发生什么情况,消息都会显示出来。我认为我使用的新筛选器有问题。请尝试缩短代码并隔离问题,这里发生的事情太多了。请不要破坏您的帖子。一旦您发布了问题,您就有问题了已将内容普遍添加到Stack Overflow社区(根据SA CC许可证)。如果您想将此帖子与您的帐户解除关联,请参阅。版主收到多个问题故意破坏的通知。我正在向帖子添加一些高质量的信息。
    <div class="m2" style="color: #FFFFFF; padding: 24px 36px;" ng-if="!(appList | NotificationsExistFilter)">No Notifications or Alerts Available</div>
    
    angular.module('notifications').filter('NotificationsExistFilter', function () {
    return function (apps) {
    if (!apps) {
      return false;
    }
    
    var retVal = false;
    angular.forEach(apps, function (app, index) {
      if (!retVal) {
        angular.forEach(app.notifications, function (value, index) {
          if (!retVal) {
            retVal = true;
          }
        })
      }
    });
    
    return retVal;
    };