Sono nuovo a AngularJs sto ottenendo i dati JSON che è in formato:tabella in base ai risultati
[
{
'StudentName':'abc',
'maths':'0',
'english':'0',
'economics':'0',
}
]
voglio calcolare ogni marchi studenti e se segni è inferiore al 40%, allora riga della tabella dovrebbe essere rosso altrimenti dovrebbe essere verde. Ho provato. HTML
<div ng-app="MyApp" ng-controller="con1">
<table id="table1">
<tr>
<th>student Name</th>
<th>History Marks</th>
<th>Maths Marks</th>
<th>Economics Marks</th>
<th>Percentage</th>
</tr>
<tr ng-repeat="x in data" ng-if="{{co(per(x))}}" ng-class="pass">
<td>{{x.StudentName}}</td>
<td>{{x.maths}}</td>
<td>{{x.economics}}</td>
<td>{{x.english}}</td>
<td>{{per(x)}}%</td>
</tr>
</table>
Script
var app = angular.module('MyApp', []);
app.controller('con1', function ($scope, $http) {
$http.get('/ajax/data').success(function (res) { $scope.data = res; });
$scope.per = function (x) {
avg = ((parseInt(x.maths) + parseInt(x.economics) + parseInt(x.english)) * 100)/300;
return avg;
};
$scope.co = function (x) { (x > 40) ? k = 1 : k = 0; return (k); }
});
css
.pass{background:green;}
.fail{background:red;}
sto ottenendo percentuale ma secondo percentuale Non ricevo il colore fila.
quando nuovo per angularjs è molto buono non utilizzare QUALSIASI jQuery – DrCord
In realtà non vedo dove viene utilizzato jQuery. – Nick
Penso che molte persone confondano jQuery con Javascript. – Scottie