从不同的模块AngularJS接入服务 [英] AngularJS access service from different module

查看:82
本文介绍了从不同的模块AngularJS接入服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于从不同的模块AngularJS接入服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆