[MEAN] First API - 5. Using $resource to setup REST app
Front-end changes:
app.js: Uinsg $resource
/** * Created by Answer1215 on 12/9/2014. */ ‘use strict‘; function MainCtrl(People) { var vm = this; vm.selectedPerson = {}; vm.people = People.query(); vm.selectPerson = function(person) { var person = People.get({id: person._id}, function() { vm.selectedPerson = angular.copy(person); vm.selectedPerson.fullName = person.firstName + " " + person.lastName; }); } } angular.module(‘app‘,[ ‘ngResource‘ ]) .controller(‘MainCtrl‘, MainCtrl) .factory(‘People‘, function($resource) { var People = $resource(‘http://localhost:3000/people/:id‘, {id: ‘@id‘}, { update: { method: ‘PUT‘ } }); return People; });
Server side keep the same.
See last post: http://www.cnblogs.com/Answer1215/p/4187965.html
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。