从不同的模块AngularJS接入服务模块、接入服务、不同、AngularJS

2023-09-13 04:33:30 作者:诺言许的快忘的也快

'use strict';

var trkiApp = angular.module('trkiApp',
[ 
  'trkiApp.tStatus'
, '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';

feed
    .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.