Last active
August 29, 2015 14:24
-
-
Save jim-clark/d5ea8d54de9955a2cfc2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| angular.module('hipposApp', []) | |
| .controller('HomeController', HomeController); | |
| function HomeController($scope, $http) { | |
| $http.get('/api/hippos') | |
| .success(function(data) { | |
| $scope.hippos = data; | |
| }); | |
| $scope.addHippo = function() { | |
| // Send a $http.post to the api with | |
| // the new hippo data in a js object. | |
| // Be sure to add the new hippo | |
| // to the $scope.hippos array. | |
| }; | |
| } |
This file contains hidden or 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" ng-app="hipposApp"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Big Hippo Depot</title> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> | |
| <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> | |
| <script type="text/javascript" src="javascripts/hippos_app.js"></script> | |
| <style> | |
| .sold { color: red; } | |
| </style> | |
| </head> | |
| <body class="container" ng-controller="HomeController"> | |
| <h1 class="jumbotron text-center">Big Hippo Depot</h1> | |
| <label>Search:</label> | |
| <input type="text" ng-model="search"> | |
| <table class="table table-striped"> | |
| <thead> | |
| <tr> | |
| <th>Name</th> | |
| <th>Weight</th> | |
| <th>Price</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr ng-class="{'sold': hippo.sold}" ng-repeat="hippo in hippos | filter:search | orderBy:'name'"> | |
| <td>{{hippo.name}}</td> | |
| <td>{{hippo.weight | number:0}}</td> | |
| <td>{{hippo.price | currency:'$':0}}</td> | |
| <td> | |
| <button class="btn btn-xs btn-warning" ng-click="hippo.sold = true" ng-hide="hippo.sold">Sell</button> | |
| </td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <hr> | |
| <h4>Add a Hippo</h4> | |
| <label>Name:</label> <input type="text" ng-model="new.name"> | |
| <label>Weight:</label> <input type="text" ng-model="new.weight"> | |
| <label>Price:</label> <input type="text" ng-model="new.price"> | |
| <button ng-click="addHippo()" class="btn btn-primary">+ Add</button> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment