1

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>
2
  • ng-if="webSummary.length" Commented Jul 28, 2016 at 13:10
  • It doesn't help, i tried it already. Commented Jul 28, 2016 at 13:12

2 Answers 2

2

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>

Sign up to request clarification or add additional context in comments.

3 Comments

good answer but need not to display visualization when all attacks counts are zero.
I have added a comment in the code: // For demo: ["System Command Injection",2]
@AbdulMajeed I have updated the answer based on your original array webSummary... Now do not show nothing.
1

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;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.