var myapp = angular.module('myapp', []);
myapp.controller('myctrl', ['$scope', function ($scope) {
$scope.alerts = {
"DISPLAY_ALERT_DETAILS": [
{
"alertRaisedUserId": 1215
, "source": 1
, "clientTimestamp": 1492732800000
, "severity": "low"
, "createdByMe": "Y"
, "notificationSubject": "dosMinus"
, "notificationDetails": "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
}
, {
"alertRaisedUserId": 1215
, "source": 1
, "clientTimestamp": 1492732800000
, "severity": "low"
, "createdByMe": "Y"
, "notificationSubject": "dosMinus"
, "notificationDetails": "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
}
, {
"alertRaisedUserId": 1215
, "source": 1
, "clientTimestamp": 1492992000000
, "severity": "low"
, "createdByMe": "Y"
, "notificationSubject": "DOS"
, "notificationDetails": "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
}
, {
"alertRaisedUserId": 1215
, "source": 1
, "clientTimestamp": 1492992000000
, "severity": "informational"
, "createdByMe": "Y"
, "notificationSubject": "EO"
, "notificationDetails": "Lorem Ipsum is simply dummy text of the printing"
}
, {
"alertRaisedUserId": 1215
, "source": 1
, "clientTimestamp": 1492992000000
, "severity": "informational"
, "createdByMe": "Y"
, "notificationSubject": "Late Sales Orders"
, "notificationDetails": "It has survived not only five centuries"
}
, {
"alertRaisedUserId": 1215
, "source": 1
, "clientTimestamp": 1492992000000
, "severity": "informational"
, "createdByMe": "Y"
, "notificationSubject": "Late Purchase Orders"
, "notificationDetails": "It was popularised in the 1960s with "
}
, {
"alertRaisedUserId": 1215
, "source": 1
, "clientTimestamp": 1492992000000
, "severity": "informational"
, "createdByMe": "Y"
, "notificationSubject": "Demand"
, "notificationDetails": "It was popularised in the 1960s with the release of Letraset sheets containing "
}
, {
"alertRaisedUserId": 1215
, "source": 1
, "clientTimestamp": 1492992000000
, "severity": "informational"
, "createdByMe": "Y"
, "notificationSubject": "Spend"
, "notificationDetails": "more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
}
, {
"alertRaisedUserId": 1215
, "source": 1
, "clientTimestamp": 1492992000000
, "severity": "informational"
, "createdByMe": "Y"
, "notificationSubject": "Inventory"
, "notificationDetails": "It was popularised in the 1960s with the release of Letraset "
}
]
}
}]);

<html ng-app="myapp">
<head> </head>
<body ng-controller="myctrl">
<div> 1. Div (Display dosMinus)</div>
<div> 2. Div (Display DOS....Etc)</div>
</body>
</html>
&#13;
答案 0 :(得分:1)
根据您的评论:
我想在1st div和&gt;中显示'dosMinus'在第二个div中保留警报。
以下是使用while
的简单代码:
ng-if
修改强>
根据不选择。每个<html ng-app="myapp">
<head> </head>
<body ng-controller="myctrl" ng-repeat="a in alerts.DISPLAY_ALERT_DETAILS">
<div> 1. Div <span ng-if="a.notificationSubject == 'dosMinus'">{{a.notificationSubject}}</span></div>
<div> 2. Div <span ng-if="a.notificationSubject != 'dosMinus'">{{a.notificationSubject}}</span></div>
</body>
</html>
出现的情况,你必须得到每个notificationSubject
的数量,并根据有选择地使用ng-if
的div2 div1。
这里设置和获取计数的JS代码:
var count = {};
$scope.alerts = ...//your JSON
for(var i=0;i<$scope.alerts.DISPLAY_ALERT_DETAILS.length;i++) {
setCount($scope.alerts.DISPLAY_ALERT_DETAILS[i].notificationSubject);
}
function setCount(notSub) {
if(count[notSub]) {
count[notSub]++;
}
else {
count[notSub] = 1;
}
}
$scope.getCount = function(notSub) {
return count[notSub];
}
并有条件地使用div,您可以从HTML中调用$scope.getCount
来计算。
<body ng-controller="myctrl" ng-repeat="a in alerts.DISPLAY_ALERT_DETAILS">
<div> 1. Div <span ng-if="getCount(a.notificationSubject)>1">{{a.notificationSubject}}</span></div>
<div> 2. Div <span ng-if="getCount(a.notificationSubject) == 1">{{a.notificationSubject}}</span></div>
</body>