node.js - Return data from node service to angularjs controller -
i following mean machine book. 1 of examples connect mongo db , retrieve users. book seems little out dated( got 2-3 errors fixed).
issue service not connect mongodb , return data. .from ui, service returns html current page.the table not being populated.
but when invoke service through postman, data
the code user retrieval this.
user service:
angular.module('userservice', []) .factory('user', function($http) { //create new object factory var userfactory = {}; //get single user userfactory.get = function(id) { return $http.get('/api/user/' + id); }; //get users userfactory.all = function() { return $http.get("/api/user/"); }; ...
shown relevant parts above.
controller:
angular.module('userctrl', ['userservice']) .controller('usercontroller', function(user) { var vm = this; //processing control vm.processing = true; //grab users on load user.all() .then(function(udata) { console.log(udata.data); vm.processing = false; vm.users = udata.data; }); })
html(all.html)
<tr ng-repeat="person in user.users"> <td>{{person._id}}</td> <td>{{person.name}}</td> <td>{{person.username}}</td> <td class="col-sm-2"> <a ng-href="/users/{{ person._id }}" class="btn btn-danger">edit</a> </td> </tr>
main angular files
angular.module('userapp', [ 'nganimate', 'app.routes', 'authservice', 'mainctrl', 'userctrl', 'userservice' ]) //app config integrate token request .config(function($httpprovider) { //attach auth interceptor http requests $httpprovider.interceptors.push('authinterceptor'); })
html file(index.html)
<body ng-app="userapp" ng-controller="maincontroller main"> .... <main class="container"> <!-- angular views --> <div ng-view></div> </main> </body>
the users table inserted above template.
route:
angular.module('app.routes', ['ngroute']) .config(function($routeprovider, $locationprovider) { $routeprovider //users .when('/users', { templateurl: 'app/views/pages/users/all.html', controller: 'usercontroller', controlleras: 'user' }); });
is issue due version mismatch? read $http service has been upgraded. help
Comments
Post a Comment