Created
December 23, 2018 12:22
-
-
Save ShanikaNishadhi/6361de5b1ec473e96170b36ee39f23c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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