Angularjs Slip no 1 solution

<html ng-app="gameApp">
<head>
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="GameController" ng-init="initialize()">
<h1>Game List</h1>
     <button ng-click="showGames()">Show Games</button>
<div ng-show="showGameList">
<h2>List of Games:</h2>
<ul>
     <li ng-repeat="game in games" ng-bind="game"></li>
</ul>
</div>
<script>
var app = angular.module('gameApp', []);
app.controller('GameController', function ($scope) {
     $scope.games = [];
     $scope.showGameList = false;
// Initialize the games array
$scope.initialize = function () {
     $scope.games = ['Chess', 'Soccer', 'Basketball', 'Cricket', 'Tennis'];
};
// Function to show the list of games
$scope.showGames = function () {
     $scope.showGameList = true;
};
});
</script>
</body>
</html>

No comments:

Post a Comment