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对于加载模块起到了缓冲的作用. ...
随机推荐
- map和string的使用方法
这个是别人写的map使用方法比較好能够看一下 http://www.cnblogs.com/anywei/archive/2011/10/27/2226830.html 怎样向数组中插入内容 http ...
- HashMap与 HashTable, Treemap的区别
(一)HashMap 1.HashMap最多只允许一条记录的键为Null;允许多条记录的值为 Null; 2.HashMap不支持线程的同步,即任一时刻可以有多个线程同时写HashMap;可能会导致数 ...
- MessageDigest和DigestUtils加密算法
总结:使用DigestUtils的方法加密的结果与messageDigest的方法加密结果一致,可使用DigestUtils替换MessageDigest 可省掉部分代码 package com.a ...
- 搭建SVN服务器详细教程
搭建SVN服务器详细教程 本教程会从最基本的下载安装到上传代码,下载代码这条线来详细讲述如何完成SVN服务器的搭建 下载并安装VisualSVN server 下载并安装TortoiseSVN 导入项 ...
- 2017-2018-1 20179209《Linux内核原理与分析》第三周作业
一.函数调用堆栈 存储程序.函数调用堆栈(高级语言起点)和中断机制是计算机工作的三大法宝.其中函数调用堆栈是本次学习的重点.先介绍一些基本的知识点: 1.ebp 在C语言中用作记录当前函数调用的基址: ...
- python+NLTK 自然语言学习处理三:如何在nltk/matplotlib中的图片中显示中文
我们首先来加载我们自己的文本文件,并统计出排名前20的字符频率 if __name__=="__main__": corpus_root='/home/zhf/word' word ...
- Linux就该这么学--了解Shell脚本
有人曾经将Shell形容是人与计算机硬件的“翻译官”,Shell作为用户与Linux系统通讯的媒介.自身也定义了各种变量和参数,并提供了诸如循环.分支等高级语言才有的控制结构特性.如何正确的使用这些功 ...
- js添加方法和邦定事件
function(obj,objArr){ if(($(obj).attr("type") == "checkbox" && $j(obj).p ...
- DataGridView自定义RichTextBox列
https://www.codeproject.com/Articles/31823/RichTextBox-Cell-in-a-DataGridView-2 RichText是用图片显示的,当Sel ...
- linux中fflush函数和printf函数 【转】
本文转载自:http://blog.chinaunix.net/uid-30058258-id-5029847.html printf是一个行缓冲函数printf函数是标准函数,最终会调用到系统调用函 ...