wiki:DeveloperGuidelines/EdenMobile/Services

EdenMobile Services

Services in EdenMobile are singleton objects providing access to global data and functionality.

Services Overview

NameFunctionality
emDBLow-level Database Access (tables)
emDialogsGeneric Popup/Popover User Dialogs
emConfigGlobal Configuration Settings
emFilesUploaded Files
emFormsIntrospective Form Building
emResourcesHigh-level Database Access (resources)
emS3JSONS3JSON codec
emServerSahana Server Access
emSQLSQL Construction (SQLite)
emSyncSynchronization with Sahana Server
emUtilsUtility Functions
emResetDatabase Reset

Accessing Services

To access a service in a controller/service/directive/filter, it must be injected.

To do this, the service can be added to the dependency list in the declaration:

EdenMobile.controller('EMSomeController', [
    '$scope', '$state', '$stateParams', 'emDialogs',    // <== depenency list
    function($scope, $state, $stateParams, emDialogs) { // <== injected dependencies become parameters

    // Accessing the service:
    emDialogs.confirmation(...);

});

...or it can be dynamically injected (e.g. to avoid circular dependencies), using the $injector service:

EdenMobile.factory('emSomeService', [
    '$injector',            // <== $injector in dependency list
    function ($injector) {  // <== $injector as parameter

    // Dynamically inject, then access the service
    var emDialogs = $injector.get('emDialogs');
    emDialogs.confirmation(...);

});
Last modified 5 years ago Last modified on 07/05/19 08:02:46
Note: See TracWiki for help on using the wiki.