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的更多相关文章

  1. Defining Go Modules

    research!rsc: Go & Versioning https://research.swtch.com/vgo shawn@a:~/gokit/tmp$ go get --helpu ...

  2. Python Tutorial 学习(六)--Modules

    6. Modules 当你退出Python的shell模式然后又重新进入的时候,之前定义的变量,函数等都会没有了. 因此, 推荐的做法是将这些东西写入文件,并在适当的时候调用获取他们. 这就是为人所知 ...

  3. Modules和Autolinking

    Modules和Autolinking OC自从Apple接手后,一直在不断改进.随着移动开发带来的OC开发者井喷式增加,客观上也要求Apple需要提供各种良好特性来支持这样一个庞大的开发者社区.iO ...

  4. Linux下Modules的概念及使用详解[转贴]

    一.什么是 modules? modules 的字面意思就是模块,在此指的是 kernel modules:简单来说,一个模块提供了一个功能,如 isofs.minix.nfs.lp 等等.传统来讲, ...

  5. 安装你自己的perl modules

    来源: http://www.cnblogs.com/itech/archive/2012/12/17/2822044.html 安装你自己的perl modules.当没有root权限的时候,需要安 ...

  6. css模块化及CSS Modules使用详解

    什么是css模块化? 为了理解css模块化思想,我们首先了解下,什么是模块化,在百度百科上的解释是,在系统的结构中,模块是可组合.分解和更换的单元.模块化是一种处理复杂系统分解成为更好的可管理模块的方 ...

  7. 开始在web中使用JS Modules

    本文由云+社区发表 作者: 原文:<Using JavaScript modules on the web> https://developers.google.com/web/funda ...

  8. CSS Modules入门教程

    为什么引入CSS Modules 或者可以这么说,CSS Modules为我们解决了什么痛点.针对以往我写网页样式的经验,具体来说可以归纳为以下几点: 全局样式冲突 过程是这样的:你现在有两个模块,分 ...

  9. python sys.modules模块

    sys.modules是一个全局字典,该字典是python启动后就加载在内存中.每当程序员导入新的模块,sys.modules都将记录这些模块.字典sys.modules对于加载模块起到了缓冲的作用. ...

随机推荐

  1. 基于redis的分布式锁二种应用场景

    “分布式锁”是用来解决分布式应用中“并发冲突”的一种常用手段,实现方式一般有基于zookeeper及基于redis二种.具体到业务场景中,我们要考虑二种情况: 一.抢不到锁的请求,允许丢弃(即:忽略) ...

  2. 关于python webpy的request

    获取get值i = web.input()keyword = i.get('keyword') 判断get值是否存在if i.has_key('keyword')

  3. Python中文编码过程中遇到的一些问题

    首先,要明确encode()和decode()的差别 encode()的作用是将Unicode编码的字符串转换为其它编码格式. 比如:st1.encode("utf-8")  这句 ...

  4. special points about git

    1 about "origin/master tracks the remote branch" 1.1 what does tracking mean? after " ...

  5. 早一天把生意做到de

    const isMobilePhoneNum = (params) => { const areaCode = params.areaCode || 'cn' const str = param ...

  6. Git 重写历史 filter-branch

    source:https://git-scm.com/book/zh/v1/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E5%86%99%E5%8E%86%E5%8F%B2 重写 ...

  7. 我的Java开发学习之旅------>Java String对象作为参数传递的问题解惑

    又是一道面试题,来测试你的Java基础是否牢固. 题目:以下代码的运行结果是? public class TestValue { public static void test(String str) ...

  8. 近年来世界各地ICO的花式骗局盘点

    很多人说区块链是骗局,其实不然,区块链是一种安全的互联网技术,可以解决当下很多行业的痛点,但也确实存在一些不法分子利用区块链进行行骗,下面整理了世界各地的一些ICO骗局,一起来看看吧. 案例一:越南I ...

  9. 20170325 ABAP调用webservice

    转自:http://www.cnblogs.com/SolisOculus/archive/2013/04/01/2993198.html 在ABAP中调用Webservice     1.创建Pro ...

  10. Mysql 外键级联

    如果表A的主关键字是表B中的字段,则该字段称为表B的外键,表A称为主表,表B称为从表.外键是用来实现参照完整性的,不同的外键约束方式将可以使两张表紧密的结合起来,特别是修改或者删除的级联操作将使得日常 ...