2016-07-28 2 views
1

양식의 서비스에서 데이터를 검색하고 있습니다.각도 js에서 ng-if를 적용하는 방법

[["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]]. 

이제 각 공격 유형의 수가 0이면 아무 것도 표시되지 않습니다. ng-if를 통해 어떻게 처리 할 수 ​​있습니까? 템플릿 코드 :

<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> 
+0

ng-if = "webSummary.length" – Lakshay

+0

도움이되지 않습니다. 이미 시도해 보았습니다. –

답변

2

당신은 할 수 있습니다 :

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>

+1

좋은 답변이지만 모든 공격 횟수가 0 일 때 시각화를 표시 할 필요는 없습니다. –

+1

코드에 주석을 추가했습니다 :'// 데모 용 : [ "System Command Injection", 2]' –

+0

@AbdulMajeed 원래 배열'webSummary'를 기반으로 답변을 업데이트했습니다 ... 이제 아무 것도 표시하지 않습니다 . –

1

당신은 컨트롤러에서

<div class="col-md-6 b-r b-light no-border-xs" ng-if="checkAttackCount()"> 
    <highchart id="chart1" config="webConfig" class="span9" ></highchart>   
</div> 

을 할 수

,536,
function checkAttackCount(){  
    for(var i=0;i<webSummary.length;i++){ 
    if(webSummary[i][1]>0){ 
     return true; 
    } 
    }  
    return false; 
} 
+1

감사합니다. –

관련 문제