Trki Trki - 3 months ago 7x
AngularJS Question

AngularJS access service from different module

'use strict';

var trkiApp = angular.module('trkiApp',
, 'trkiApp.feed'

var tStatus = angular.module('trkiApp.tStatus', [])
.factory('Status', ['$q',

var feed = angular.module('trkiApp.feed', [])

And now i dont understand how is possible that i can access the service Status which is defined on another module?

'use strict';

.controller('FeedController', ['$scope','$http','Status',

I should not right? But somehow i am...or is that a correct behaviour?


A Module is a collection of configuration and run blocks which get applied to the application during the bootstrap process. Modules can list other modules as their dependencies. Depending on a module implies that required module needs to be loaded before the requiring module is loaded.

var myModule = angular.module('myModule', ['module1','module2']);

When you injected your module, the services got registered during the configuration phase and you could access them, so to make a long story short ,it's the correct behavior and the core fundamentals of dependency injection in Angular. For example

angular.module('module1').service('appservice', function(appservice){

var serviceCall= $'api/getUser(),"Role");});

So how it can be accessed using angular.module('mymodule');

    var Servicedata= appservice.ServiceCall('role');

This how it can be accessed. If anyone has another suggestion please say so.