Can someone assist me in displaying a list of data from an array on the loading page? Additionally, I need help with showing the selected value from a dropdown once it is chosen.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>js bin</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<style>
.text-red {
color: red;
}
.text-green {
color: green;
}
.text-black {
color: black;
}
</style>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.cars = ["Porsche", "Bentley", "Audi", "Ferrari", "BMW", "Ford"];
$scope.cars.sort();
$scope.car_obj = [];
for (var i=0; i<$scope.cars.length; i++){
$scope.car_obj.push({name: $scope.cars[i], selected: false, nonSelected: false})
}
$scope.getCheckedCount = function(type){
return $scope.car_obj.filter(function(car){return car[type]}).length;
}
});
</script>
<body>
<div class="container-fluid" ng-app="myApp" ng-controller="myCtrl">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>
<div>nonSelected: {{getCheckedCount('nonSelected')}}</div>
<ul style="list-style-type:none">
<li id="list" ng-repeat="x in car_obj">
<input type="checkbox" ng-model="x.selected" ng-disabled="x.nonSelected"/>
<input type="checkbox" ng-model="x.nonSelected" ng-disabled="x.selected"/><span ng-class="{'text-red': x.nonSelected, 'text-green': x.selected}">{{x.name}}</span></li>
</li>
</ul>
</div>
</div>
</body>
</html>
https://i.sstatic.net/Du5ok.jpg
I'm looking for assistance in showcasing the array data upon page load and displaying the selected value from the dropdown menu when a selection is made.