angular.module('yds').directive('ydsAggregate', ['Data', 'DashboardService', '$sce', '$timeout',
    function(Data, DashboardService, $sce, $timeout) {
        return {
            restrict: 'E',
            scope: {
                projectId: '@',     // Project ID of chart
                viewType: '@',      // View type of chart
                dashboardId: '@',   // ID used for getting selected year range from DashboardService
                lang: '@',          // Language
                iconSize: '@',      // Icon size for FontAwesome icon (2-5)
                setOnInit: '@',     // If true, will set this aggregate's view type in DashboardService on init
                extraParams: '='    // Extra parameters to send
            },
            templateUrl: ((typeof Drupal != 'undefined') ? Drupal.settings.basePath + Drupal.settings.yds_project.modulePath +'/' : '') + 'templates/aggregate.html',
            link: function (scope) {
                var projectId = scope.projectId;
                var viewType = scope.viewType;
                var dashboardId = scope.dashboardId;
                var lang = scope.lang;
                var setOnInit = scope.setOnInit;
                var iconSize = scope.iconSize;

                var initialized = false;

                // If project attribute is undefined, set default value
                if (_.isUndefined(projectId) || projectId.trim() == "")
                    projectId = "none";

                // If view type is undefined, show error
                if (_.isUndefined(viewType) || viewType.trim() == "") {
                    console.error("View type not defined!");
                    return;
                }

                // If dashboardId is undefined, show error
                if (_.isUndefined(dashboardId) || dashboardId.trim() == "") {
                    dashboardId = "default";
                }

                // If language is undefined, set default value
                if (_.isUndefined(lang) || lang.trim() == "")
                    lang = "en";

                // If iconSize is undefined, set default value
                if (_.isUndefined(iconSize) || iconSize.trim() == "")
                    iconSize = "4";

                var getAggregateData = function() {
                    // Get data for aggregate from API to set variables
                    Data.getAggregate(projectId, viewType, lang, scope.extraParams).then(function(response) {
                        // Get value and label
                        scope.label = $sce.trustAsHtml(response.data.label);
                        scope.value = response.data.value;

                        // Get icon class
                        scope.iconClass = _.first(response.view).icon + " fa-" + iconSize + "x";

                        // Get color and create panel and panel heading styles
                        var color = _.first(response.view).color;

                        scope.panelStyle = {
                            "border-color": color
                        };

                        scope.panelHeadingStyle = {
                            "background-color": color,
                            "border-color": color,
                            "color": "#FFFFFF"
                        };

                        if (setOnInit == "true" && !initialized && _.isEmpty(DashboardService.getViewType(dashboardId))) {
                            scope.setViewType();
                        }

                        initialized = true;
                    });
                };

                /**
                 * Sets the view type to this aggregate component's view type in DashboardService
                 */
                scope.setViewType = function() {
                    DashboardService.setViewType(dashboardId, {
                        type: viewType,
                        panelStyle: scope.panelStyle,
                        panelHeadingStyle: scope.panelHeadingStyle
                    });
                };

                // Watch for changes in extra parameters of aggregate and update it
                scope.$watch("extraParams", function(newValue, oldValue) {
                    if (!_.isEqual(newValue, oldValue)) {
                        getAggregateData();
                    }
                });

                // Create aggregate for the first time
                $timeout(function() {
                    if (!initialized) {
                        getAggregateData();
                    }
                });
            }
        };
    }
]);

@@ -2685,16 +2685,77 @@
 n class%0A
+                        if (!_.isEmpty(response.view)) %7B%0A    
         
@@ -2864,24 +2864,28 @@
             
+ 
+   
 // Get color
@@ -2947,24 +2947,28 @@
             
+    
 var color = 
@@ -3014,32 +3014,36 @@
                 
+ 
+   
 scope.panelStyle
@@ -3039,32 +3039,36 @@
 .panelStyle = %7B%0A
+    
                 
@@ -3117,36 +3117,44 @@
                 
+  
+  
 %7D;%0A%0A
+    
                 
@@ -3217,16 +3217,20 @@
         
+   
+ 
 %22backgro
@@ -3268,32 +3268,36 @@
                 
+    
 %22border-color%22: 
@@ -3295,32 +3295,36 @@
 -color%22: color,%0A
+    
                 
@@ -3370,36 +3370,44 @@
                 
-%7D;%0A%0A
+    %7D;%0A%0A    
                 
@@ -3533,32 +3533,36 @@
                 
+    
 scope.setViewTyp
@@ -3562,24 +3562,54 @@
 ViewType();%0A
+                            %7D%0A
             

Make Aggregate not show error when there is no view