Guest User

Untitled

a guest
Jan 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. [ { _id: 5880e3a737893c04c87e30bf,
  2. name: 'Tom',
  3. number: '4444444444' },
  4. { _id: 5880e44637893c04c87e30c0,
  5. name: 'Tracy',
  6. number: '123412345' },
  7. { _id: 5880e44637893c04c87e30c1,
  8. name: 'tucker',
  9. number: '1234456666' } ]
  10.  
  11. var express = require('express');
  12. var app = express();
  13. var mongojs = require('mongojs');
  14. var db = mongojs('contactlist', ['contactlist']);
  15.  
  16. app.use(express.static(__dirname + "/public"));
  17.  
  18. app.get('/contactlist', function(req, res){
  19.  
  20. db.contactlist.find(function (err, docs) {
  21. console.log(docs);
  22. res.json(docs);
  23. });
  24.  
  25. });
  26.  
  27. app.listen(3000);
  28. console.log("Server running on port 3000");
  29.  
  30. var myApp = angular.module('myApp', []);
  31.  
  32. myApp.controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
  33.  
  34. $http.get('/contactlist').success(function(response){
  35. console.log("I got the data i requested");
  36. $scope.contactlist = response.data;
  37. });
  38.  
  39. }]);
  40.  
  41. <!DOCTYPE html>
  42. <html ng-app="myApp">
  43. <head>
  44. <title>Contact List App</title>
  45. <!-- Latest compiled and minified CSS -->
  46. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  47.  
  48. <!-- Optional theme -->
  49. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
  50. </head>
  51. <body>
  52. <div class="containter" ng-controller="AppCtrl">
  53. <h1>Contact List App</h1>
  54. <table class="table">
  55. <thead>
  56. <tr>
  57. <th>Name</th>
  58. <th>Email</th>
  59. <th>Number</th>
  60. </tr>
  61. </thead>
  62. <tbody>
  63. <tr ng-repeat="contact in contactlist">
  64. <td>{{contact.name}}</td>
  65. <td>{{contact.email}}</td>
  66. <td>{{contact.number}}</td>
  67. </tr>
  68. </tbody>
  69. </table>
  70. </div>
  71.  
  72. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  73. <script src="controllers/controller.js"></script>
  74. </body>
  75. </html>
Advertisement
Add Comment
Please, Sign In to add comment