Skip to content

Instantly share code, notes, and snippets.

@ShanikaNishadhi
Created December 23, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShanikaNishadhi/6361de5b1ec473e96170b36ee39f23c0 to your computer and use it in GitHub Desktop.
Save ShanikaNishadhi/6361de5b1ec473e96170b36ee39f23c0 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myController">
<p>Pass Students{{submit(list)}}</p>
<p style="padding-left: 20px">{{pass_list}}</p>
<p>Failed Students</p>
<p style="padding-left: 20px">{{fail_list}}</p>
</div>
<script>
var myApp = angular.module('myApp', []);
myApp.controller('myController', ['$scope', function ($scope) {
$scope.list = {
Adam : {marks : '75', grade : 'P'},
Mike : {marks : '45', grade : 'F'},
Dino : {marks : '85', grade : 'P'},
Anna : {marks : '35', grade : 'F'},
Lucy : {marks : '80', grade : 'P'}
};
$scope.submit = function (list) {
var passStudents = [];
var failStudents = [];
angular.forEach(list, function (value, key) {
if (value.grade == "P")
passStudents.push(key);
else
failStudents.push(key);
});
if (passStudents.length > 0)
$scope.pass_list = passStudents.toString();
if (failStudents.length > 0)
$scope.fail_list = failStudents.toString();
}
}]);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment