I have a user table in the database behind my angular application. I have separate accounts for logging in, registering and managing users as separate pages.
I want to define a service that stores a list of user objects as they are loaded. If a new query is requested from the database, the record must be transferred to the service, and the service must return the existing object, if any, or create a new one otherwise. In addition, the service must be able to disable unused objects when specified, and these objects must be installed on uninitialized user objects. If a create call is subsequently created, instead of creating a new object, it should just install the old object.
I also want to define a service (but should it not be called a service?), Which defines a user object. Thus, the user will not be just a parsed JSON object, but will also be decorated with methods for tracking any changes and either committing or reverting these changes.
Since I have separate pages that use a custom object. I would like to include services on every page. According to AngularJS docs, in order to register a service, I need to do something like:
var myModule = angular.module('myModule', []);
myModule.factory('serviceId', function() {
var shinyNewServiceInstance;
return shinyNewServiceInstance;
});
However, this service (as far as I can tell) is built-in. I do not want to copy and paste the code. I want to define a service in a separate file. The service does not need to know which module calls it. It must exist only to join the module.
I tried to create a separate file services/user.jswith the following syntax:
$provide.service('users', UserService);
, , , $ undefined. , $provide , .
, ? , , ?