AngularJs(Part 4)--Modules depending on other Modules
Angular does an excellent job of managing object dependencies. it can even take care of module dependencies.
So we can easily group releated services into one module, and make other modules dependent on it.
angular.module('my',['my1','my2']);
the preceding code create a module named "my" which dependent on two other modules "my1" and "my2".
So modules can dependent on other modules and services can dependent on other services.
and this raises several interesting questions, which are as follows:
1. Can a service defined in one AngularJS module depend on services in another module?
2. Can services defined in a child module depend on a service in a parent module, or only on services defined in child modules?
3. Can we have module-private services visible only in a certain module?
4. Can we have several services with the same name defined in different modules?
angular.module('app',['engines'])
.factory('car',function(dieselEngine){
return {
info:function(){
console.log(dieselEngine.type);
}
};
});
angular.module('engines',[])
.factory('dieselEngine',function(){
return {
type:'a sport car'
};
});
above code can execute with no problems.
what's more surprising is that services defined on sibling modules are also visible to each other. check below code snippet out:
angular.module('my',['car','engines']);
angular.module('car',[])
.factory('carlog',function(dieselEngine){
return {
info:function(){
console.log(dieselEngine.type);
}
};
});
angular.module('engines',[])
.factory('dieselEngine',function(){
return {
type:'a sport car'
};
});
conclusion: a service defined in one of the application's modules is visible to all the other modules. In other words,
hierarchy of modules doesn't influence services' visibility to other modules. when Angujar bootstraps an application,
it combines all the services defined across all the modules into one application, that is , global namespace.
Since Angular combines all the services from all modules into one big namespace.
there can be only one service with a given name.
currently, there is no way to restrict service's visibility to the other modules.
AngularJs(Part 4)--Modules depending on other Modules的更多相关文章
- Defining Go Modules
research!rsc: Go & Versioning https://research.swtch.com/vgo shawn@a:~/gokit/tmp$ go get --helpu ...
- Python Tutorial 学习(六)--Modules
6. Modules 当你退出Python的shell模式然后又重新进入的时候,之前定义的变量,函数等都会没有了. 因此, 推荐的做法是将这些东西写入文件,并在适当的时候调用获取他们. 这就是为人所知 ...
- Modules和Autolinking
Modules和Autolinking OC自从Apple接手后,一直在不断改进.随着移动开发带来的OC开发者井喷式增加,客观上也要求Apple需要提供各种良好特性来支持这样一个庞大的开发者社区.iO ...
- Linux下Modules的概念及使用详解[转贴]
一.什么是 modules? modules 的字面意思就是模块,在此指的是 kernel modules:简单来说,一个模块提供了一个功能,如 isofs.minix.nfs.lp 等等.传统来讲, ...
- 安装你自己的perl modules
来源: http://www.cnblogs.com/itech/archive/2012/12/17/2822044.html 安装你自己的perl modules.当没有root权限的时候,需要安 ...
- css模块化及CSS Modules使用详解
什么是css模块化? 为了理解css模块化思想,我们首先了解下,什么是模块化,在百度百科上的解释是,在系统的结构中,模块是可组合.分解和更换的单元.模块化是一种处理复杂系统分解成为更好的可管理模块的方 ...
- 开始在web中使用JS Modules
本文由云+社区发表 作者: 原文:<Using JavaScript modules on the web> https://developers.google.com/web/funda ...
- CSS Modules入门教程
为什么引入CSS Modules 或者可以这么说,CSS Modules为我们解决了什么痛点.针对以往我写网页样式的经验,具体来说可以归纳为以下几点: 全局样式冲突 过程是这样的:你现在有两个模块,分 ...
- python sys.modules模块
sys.modules是一个全局字典,该字典是python启动后就加载在内存中.每当程序员导入新的模块,sys.modules都将记录这些模块.字典sys.modules对于加载模块起到了缓冲的作用. ...
随机推荐
- IOS简单的渐变绘制
本文转载至 http://www.cnblogs.com/flychen/archive/2012/09/18/2690264.html 前几个星期项目中的音乐列表左边要添加阴影,做成平滑的效果.如图 ...
- python 基础 1.5 python数据类型(二)--列表常用方法示例
#/usr/bin/python #coding=utf-8 #@Time :2017/10/12 23:30 #@Auther :liuzhenchuan #@File :列表.py lis ...
- 内存MCE错误导致暴力扩充messages日志 以及chattr记录
由于放假,好久没登过服务器,今天登上服务器查看日志意外发现:/var/log/messages文件竟然被撑到20多个G!!!赶紧查看是什么情况,首先,20多个G的文件根本无法查看,因此,我想到了spl ...
- EasyNVR H5直播流媒体解决方案前端构建之:如何播放自动适配RTMP/HLS直播播放
之前在进行EasyNVR多屏开发的时候,由于多屏功能不需要在手机端展示出来(pc多播放为RTMP,手机端播放为HLS),因此只注意到了引用videojs来进行rtmp的播放.由于不同项目需求不同,对h ...
- intellij idea同一个窗口打开多个项目
1 将多个maven项目放在同一个目录 2 file --> open该目录 intellij 将会加载该目录下所有的项目. 3 依赖加载 maven projects--->" ...
- 使用active mq
1 windows下使用active mq 1.1 下载active mq 1.2 点击根目录\bin\win64\activemq.bat运行 1.3 登陆查看 http://localhost:8 ...
- 【题解】HNOI2013比赛
[题解][P3230 HNOI2013]比赛 将得分的序列化成样例给的那种表格,发现一行和一列是同时确定的.这个表格之前是正方形的,后来长宽都减去一,还是正方形.问题形式是递归的.这就启示我们可以把这 ...
- Linux搭建FTP服务器实战
首先准备一台Linux系统机器(虚拟机也可), 检测出是否安装了vsftpd软件: rpm -qa |grep vsftpd 如果没有输出结果,就是没有安装. 使用命令安装,安装过程中会有提示,直接输 ...
- linux日志系统介绍 —— syslog(),openlog(),closelog()
函数使用介绍 这里面的三个函数openlog, syslog.closelog是一套系统日志写入接口.另外那个vsyslog和syslog功能一样,仅仅是參数格式不同. 通常.sysl ...
- angularJs-HelloWorld
AngularJS使用了不同的方法,它尝试去补足HTML本身在构建应用方面的缺陷.AngularJS通过使用我们称为标识符(directives)的结构,让浏览器能够识别新的语法. 1使用双大括号{{ ...