wiki:DeveloperGuidelines/EdenMobile/Services

Version 2 (modified by Dominic König, 4 years ago) ( diff )

--

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

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(...);

});
Note: See TracWiki for help on using the wiki.