Now that we have the REST endpoints in place, we are now able to call them from AngularJS! To create a service for login
, logout
, and register
, it only needs to interact with $resource
, from AngularJS, to call the REST endpoints as shown in the following code:
angular.module('user.services', ['ngResource']). service('User', function ($resource) { var loadUser = function (success) { $resource('/chapter10/rest/account').get(function (userData) { if (userData.userId) { if (success) { success(userData); } } }); }; this.register = function (user, success, error) { $resource('/chapter10/rest/account/register').save(user, function (response) { if (response.success) { success(); } else { error(); } }, error); ...