Advertisement
Guest User

Untitled

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