Reputation: 79
I am retrieving data from service in the form.
[["Sql Injection",0],["Proxy Abuse",0],["Spam",0],["Information and Source Code Leakage",0],["System Command Injection",0],["Cross-Site Request Forgery",0],["Session Hijacking",0],["PHP Injection",0],["Request Anomaly",0],["Local/Remote File Inclusion",0],["Cross-Site Scripting",0]].
Now i want that if counts of each attack type are zero then nothing display. How can i handle this through ng-if. Template code:
<div class="col-md-6 b-r b-light no-border-xs" ng-show="webSummary[0]">
<highchart id="chart1" config="webConfig" class="span9" ></highchart>
</div>
Upvotes: 1
Views: 55
Reputation: 19090
You can do:
angular
.module('MyApp', [])
.controller('MyController', function($scope) {
$scope.webSummary = [["Sql Injection",0],["Proxy Abuse",0],["Spam",0],["Information and Source Code Leakage",0],["System Command Injection",0],["Cross-Site Request Forgery",0],["Session Hijacking",0],["PHP Injection",0],["Request Anomaly",0],["Local/Remote File Inclusion",0],["Cross-Site Scripting",0]];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="MyApp" ng-controller="MyController">
<div class="col-md-6 b-r b-light no-border-xs"
ng-repeat="ws in webSummary"
ng-if="ws[1]">
<highchart id="chart1" config="webConfig" class="span9"></highchart>
</div>
</div>
Upvotes: 2
Reputation: 7919
You can do
<div class="col-md-6 b-r b-light no-border-xs" ng-if="checkAttackCount()">
<highchart id="chart1" config="webConfig" class="span9" ></highchart>
</div>
In controller
function checkAttackCount(){
for(var i=0;i<webSummary.length;i++){
if(webSummary[i][1]>0){
return true;
}
}
return false;
}
Upvotes: 1