zoukankan      html  css  js  c++  java
  • 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.
        
        
        
        

  • 相关阅读:
    程序员小抄大全
    赢在中国“80后30个忠告”
    Eclipse下python插件(pydev)的安装
    PDF加密文件的解密和打印
    中美欧联手打击僵尸网络 深化安全合作 狼人:
    入侵奥巴马帐号法国黑客自称是一个好黑客 狼人:
    Firefox 3.6.3版率先修复黑客大赛所曝漏洞 狼人:
    2009年全球安全SaaS市场收入比2008年增长70% 狼人:
    微软等厂商高管谈安全云面临的挑战 狼人:
    报告称Windows7不安全 管理员权限是罪魁祸首 狼人:
  • 原文地址:https://www.cnblogs.com/formyjava/p/4166313.html
Copyright © 2011-2022 走看看