Modifications to lb-services.js
I noticed that the loopback angular SDK generated code, lb-services.js, has some modifications to it(such as interceptors on some of the User methods).
I have my gruntfile set up so that lb-services.js gets re-generated every time. The app is in development and I'll be making changes to the models frequently so I re-generate lb-services.js in my grunt workflow.
Is there a way to take the modifications you have made to lb-services.js and put them in a different file? If this could be done in such a way that I can re-generate lb-services.js and still keep the functionality of the modifications you have on it, it would be a huge help.
If not, what is the right way of dealing with frequent changes in the model and needing to re-generate lb-services.js often? Do you have to manually merge in the changes in this example every time? Or is there a better way?
I noticed that the loopback angular SDK generated code, lb-services.js, has some modifications to it(such as interceptors on some of the User methods).
If you are referring to the changes made in 4cfc2bcd, those changes were made by a newer version of the code generator. No custom code is involved.
Is there a way to take the modifications you have made to lb-services.js and put them in a different file? If this could be done in such a way that I can re-generate lb-services.js and still keep the functionality of the modifications you have on it, it would be a huge help.
If not, what is the right way of dealing with frequent changes in the model and needing to re-generate lb-services.js often? Do you have to manually merge in the changes in this example every time? Or is there a better way?
What kind of changes are you trying to make?
The correct approach is to implement your customization using Angular tools like $http interceptors and decorators.
Ah that's strange. My generated code looks pretty different. It doesn't have any of the interceptors in the user code. I believe I have the latest version of loopback and grunt-loopback-sdk-angular.
Running "loopback_sdk_angular:services" (loopback_sdk_angular) task
>> Loaded LoopBack app "../<appname>/server/server.js"
Generating "lbServices" for the API endpoint "/api"
Warning: scope User.accessTokens targets class "AccessToken", which is not exposed
via remoting. The Angular code for this scope won't be generated.
>> Generated Angular services file "www/components/lb-services.js"
Is docular required in the grunt workflow? I excluded it since I can't get it to work. It always seems to blow up, and when I do an npm update it blows up even worse(walls upon walls of text talking about errors with deprecated function calls).
Anyway, here's the lb-services.js that I end up getting(note the lack of interceptors in the User code):
(function(window, angular, undefined) {'use strict';
var urlBase = "/api";
/**
* @ngdoc overview
* @name lbServices
* @module
* @description
*
* The `lbServices` module provides services for interacting with
* the models exposed by the LoopBack server via the REST API.
*
*/
var module = angular.module("lbServices", ['ngResource']);
/**
* @ngdoc object
* @name lbServices.User
* @object
*
* @description
*
* A $resource object for interacting with the `User` model.
*
* ## Example
*
* See
* {@link http://docs.angularjs.org/api/ngResource.$resource#example $resource}
* for an example of using this object.
*
*/
module.factory(
"User",
['LoopBackResource', 'LoopBackAuth', '$injector', function(Resource, LoopBackAuth, $injector) {
var R = Resource(
urlBase + "/Users/:id",
{ 'id': '@id' },
{
/**
* @ngdoc method
* @name lbServices.User#login
* @methodOf lbServices.User
*
* @description
*
* Login a user with username/email and password
*
* @param {Object=} parameters Request parameters.
*
* - `include` – `{string=}` - Related objects to include in the response. See the description of return value for more details.
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* The response body contains properties of the AccessToken created on login.
* Depending on the value of `include` parameter, the body may contain additional properties:
*
* - `user` - `{User}` - Data of the currently logged in user. (`include=user`)
*
*
*/
"login": {
url: urlBase + "/Users/login",
method: "POST",
},
/**
* @ngdoc method
* @name lbServices.User#logout
* @methodOf lbServices.User
*
* @description
*
* Logout a user with access token
*
* @param {Object=} parameters Request parameters.
*
* This method does not accept any parameters.
* Supply an empty object or omit this argument altogether.
*
* @param {Object} postData Request data.
*
* - `access_token` – `{string}` - Do not supply this argument, it is automatically extracted from request headers.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* This method returns no data.
*/
"logout": {
url: urlBase + "/Users/logout",
method: "POST",
},
/**
* @ngdoc method
* @name lbServices.User#confirm
* @methodOf lbServices.User
*
* @description
*
* Confirm a user registration with email verification token
*
* @param {Object=} parameters Request parameters.
*
* - `uid` – `{string}` -
*
* - `token` – `{string}` -
*
* - `redirect` – `{string}` -
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* This method returns no data.
*/
"confirm": {
url: urlBase + "/Users/confirm",
method: "GET",
},
/**
* @ngdoc method
* @name lbServices.User#resetPassword
* @methodOf lbServices.User
*
* @description
*
* Reset password for a user with email
*
* @param {Object=} parameters Request parameters.
*
* This method does not accept any parameters.
* Supply an empty object or omit this argument altogether.
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* This method returns no data.
*/
"resetPassword": {
url: urlBase + "/Users/reset",
method: "POST",
},
/**
* @ngdoc method
* @name lbServices.User#prototype$__findById__accessTokens
* @methodOf lbServices.User
*
* @description
*
* Find a related item by id for accessTokens
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - User id
*
* - `fk` – `{*}` - Foreign key for accessTokens
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"prototype$__findById__accessTokens": {
url: urlBase + "/Users/:id/accessTokens/:fk",
method: "GET",
},
/**
* @ngdoc method
* @name lbServices.User#prototype$__destroyById__accessTokens
* @methodOf lbServices.User
*
* @description
*
* Delete a related item by id for accessTokens
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - User id
*
* - `fk` – `{*}` - Foreign key for accessTokens
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* Data properties:
*
* - `` – `{undefined=}` -
*/
"prototype$__destroyById__accessTokens": {
url: urlBase + "/Users/:id/accessTokens/:fk",
method: "DELETE",
},
/**
* @ngdoc method
* @name lbServices.User#prototype$__updateById__accessTokens
* @methodOf lbServices.User
*
* @description
*
* Update a related item by id for accessTokens
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - User id
*
* - `fk` – `{*}` - Foreign key for accessTokens
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"prototype$__updateById__accessTokens": {
url: urlBase + "/Users/:id/accessTokens/:fk",
method: "PUT",
},
/**
* @ngdoc method
* @name lbServices.User#prototype$__get__accessTokens
* @methodOf lbServices.User
*
* @description
*
* Queries accessTokens of User.
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - User id
*
* - `filter` – `{object=}` -
*
* @param {Function(Array.<Object>, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Array.<Object>} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"prototype$__get__accessTokens": {
url: urlBase + "/Users/:id/accessTokens",
method: "GET",
isArray: true,
},
/**
* @ngdoc method
* @name lbServices.User#prototype$__create__accessTokens
* @methodOf lbServices.User
*
* @description
*
* Creates a new instance in accessTokens of this model.
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - User id
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"prototype$__create__accessTokens": {
url: urlBase + "/Users/:id/accessTokens",
method: "POST",
},
/**
* @ngdoc method
* @name lbServices.User#prototype$__delete__accessTokens
* @methodOf lbServices.User
*
* @description
*
* Deletes all accessTokens of this model.
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - User id
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* This method returns no data.
*/
"prototype$__delete__accessTokens": {
url: urlBase + "/Users/:id/accessTokens",
method: "DELETE",
},
/**
* @ngdoc method
* @name lbServices.User#prototype$__count__accessTokens
* @methodOf lbServices.User
*
* @description
*
* Counts accessTokens of User.
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - User id
*
* - `where` – `{object=}` - Criteria to match model instances
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* Data properties:
*
* - `count` – `{number=}` -
*/
"prototype$__count__accessTokens": {
url: urlBase + "/Users/:id/accessTokens/count",
method: "GET",
},
/**
* @ngdoc method
* @name lbServices.User#create
* @methodOf lbServices.User
*
* @description
*
* Create a new instance of the model and persist it into the data source
*
* @param {Object=} parameters Request parameters.
*
* This method does not accept any parameters.
* Supply an empty object or omit this argument altogether.
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"create": {
url: urlBase + "/Users",
method: "POST",
},
/**
* @ngdoc method
* @name lbServices.User#upsert
* @methodOf lbServices.User
*
* @description
*
* Update an existing model instance or insert a new one into the data source
*
* @param {Object=} parameters Request parameters.
*
* This method does not accept any parameters.
* Supply an empty object or omit this argument altogether.
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"upsert": {
url: urlBase + "/Users",
method: "PUT",
},
/**
* @ngdoc method
* @name lbServices.User#exists
* @methodOf lbServices.User
*
* @description
*
* Check whether a model instance exists in the data source
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - Model id
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* Data properties:
*
* - `exists` – `{boolean=}` -
*/
"exists": {
url: urlBase + "/Users/:id/exists",
method: "GET",
},
/**
* @ngdoc method
* @name lbServices.User#findById
* @methodOf lbServices.User
*
* @description
*
* Find a model instance by id from the data source
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - Model id
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"findById": {
url: urlBase + "/Users/:id",
method: "GET",
},
/**
* @ngdoc method
* @name lbServices.User#find
* @methodOf lbServices.User
*
* @description
*
* Find all instances of the model matched by filter from the data source
*
* @param {Object=} parameters Request parameters.
*
* - `filter` – `{object=}` - Filter defining fields, where, orderBy, offset, and limit
*
* @param {Function(Array.<Object>, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Array.<Object>} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"find": {
url: urlBase + "/Users",
method: "GET",
isArray: true,
},
/**
* @ngdoc method
* @name lbServices.User#findOne
* @methodOf lbServices.User
*
* @description
*
* Find first instance of the model matched by filter from the data source
*
* @param {Object=} parameters Request parameters.
*
* - `filter` – `{object=}` - Filter defining fields, where, orderBy, offset, and limit
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"findOne": {
url: urlBase + "/Users/findOne",
method: "GET",
},
/**
* @ngdoc method
* @name lbServices.User#updateAll
* @methodOf lbServices.User
*
* @description
*
* Update instances of the model matched by where from the data source
*
* @param {Object=} parameters Request parameters.
*
* - `where` – `{object=}` - Criteria to match model instances
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* This method returns no data.
*/
"updateAll": {
url: urlBase + "/Users/update",
method: "POST",
},
/**
* @ngdoc method
* @name lbServices.User#deleteById
* @methodOf lbServices.User
*
* @description
*
* Delete a model instance by id from the data source
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - Model id
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* This method returns no data.
*/
"deleteById": {
url: urlBase + "/Users/:id",
method: "DELETE",
},
/**
* @ngdoc method
* @name lbServices.User#count
* @methodOf lbServices.User
*
* @description
*
* Count instances of the model matched by where from the data source
*
* @param {Object=} parameters Request parameters.
*
* - `where` – `{object=}` - Criteria to match model instances
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* Data properties:
*
* - `count` – `{number=}` -
*/
"count": {
url: urlBase + "/Users/count",
method: "GET",
},
/**
* @ngdoc method
* @name lbServices.User#prototype$updateAttributes
* @methodOf lbServices.User
*
* @description
*
* Update attributes for a model instance and persist it into the data source
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - User id
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
"prototype$updateAttributes": {
url: urlBase + "/Users/:id",
method: "PUT",
},
}
);
/**
* @ngdoc method
* @name lbServices.User#updateOrCreate
* @methodOf lbServices.User
*
* @description
*
* Update an existing model instance or insert a new one into the data source
*
* @param {Object=} parameters Request parameters.
*
* This method does not accept any parameters.
* Supply an empty object or omit this argument altogether.
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `User` object.)
* </em>
*/
R["updateOrCreate"] = R["upsert"];
/**
* @ngdoc method
* @name lbServices.User#update
* @methodOf lbServices.User
*
* @description
*
* Update instances of the model matched by where from the data source
*
* @param {Object=} parameters Request parameters.
*
* - `where` – `{object=}` - Criteria to match model instances
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* This method returns no data.
*/
R["update"] = R["updateAll"];
/**
* @ngdoc method
* @name lbServices.User#destroyById
* @methodOf lbServices.User
*
* @description
*
* Delete a model instance by id from the data source
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - Model id
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* This method returns no data.
*/
R["destroyById"] = R["deleteById"];
/**
* @ngdoc method
* @name lbServices.User#removeById
* @methodOf lbServices.User
*
* @description
*
* Delete a model instance by id from the data source
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - Model id
*
* @param {Function(Object, Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {Function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @return {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* This method returns no data.
*/
R["removeById"] = R["deleteById"];
return R;
}]);
module
.factory('LoopBackAuth', function() {
var props = ['accessTokenId', 'currentUserId'];
function LoopBackAuth() {
var self = this;
props.forEach(function(name) {
self[name] = load(name);
});
this.rememberMe = undefined;
this.currentUserData = null;
}
LoopBackAuth.prototype.save = function() {
var self = this;
var storage = this.rememberMe ? localStorage : sessionStorage;
props.forEach(function(name) {
save(storage, name, self[name]);
});
};
LoopBackAuth.prototype.setUser = function(accessTokenId, userId, userData) {
this.accessTokenId = accessTokenId;
this.currentUserId = userId;
this.currentUserData = userData;
}
LoopBackAuth.prototype.clearUser = function() {
this.accessTokenId = null;
this.currentUserId = null;
this.currentUserData = null;
}
return new LoopBackAuth();
// Note: LocalStorage converts the value to string
// We are using empty string as a marker for null/undefined values.
function save(storage, name, value) {
var key = '$LoopBack$' + name;
if (value == null) value = '';
storage[key] = value;
}
function load(name) {
var key = '$LoopBack$' + name;
return localStorage[key] || sessionStorage[key] || null;
}
})
.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('LoopBackAuthRequestInterceptor');
}])
.factory('LoopBackAuthRequestInterceptor', [ '$q', 'LoopBackAuth',
function($q, LoopBackAuth) {
return {
'request': function(config) {
if (LoopBackAuth.accessTokenId) {
config.headers.authorization = LoopBackAuth.accessTokenId;
} else if (config.__isGetCurrentUser__) {
// Return a stub 401 error for User.getCurrent() when
// there is no user logged in
var res = {
body: { error: { status: 401 } },
status: 401,
config: config,
headers: function() { return undefined; }
};
return $q.reject(res);
}
return config || $q.when(config);
}
}
}])
.factory('LoopBackResource', [ '$resource', function($resource) {
return function(url, params, actions) {
var resource = $resource(url, params, actions);
// Angular always calls POST on $save()
// This hack is based on
// http://kirkbushell.me/angular-js-using-ng-resource-in-a-more-restful-manner/
resource.prototype.$save = function(success, error) {
// Fortunately, LoopBack provides a convenient `upsert` method
// that exactly fits our needs.
var result = resource.upsert.call(this, {}, this, success, error);
return result.$promise || result;
}
return resource;
};
}]);
})(window, window.angular);
Are you using the built-in User class? There is a bug in the code generator where it did not recognise the built-in User model as a "user-like" model - see https://github.com/strongloop/loopback-sdk-angular/pull/75.
I have just released a new version v1.2.1 with the fix. Please let me know if it solves the problem for you.
Yep I was using the default User class. I just grabbed the new version and it worked. Thanks!