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.
        
        
        
        

  • 相关阅读:
    关于SubSonic3.0查询或更新时出现System.NullReferenceException异常的处理
    SubSonic3.0使用例子
    Hive:ORC File Format存储格式详解
    HiveQL之Sort by、Distribute by、Cluster by、Order By详解
    Hive之import和export使用详解
    手动安装cloudera manager 5.x(tar包方式)详解
    初次安装hive-2.1.0启动报错问题解决方法
    LAMP下安装zabbix流水
    ESXI虚拟机磁盘管理(精简-厚置-精简)
    VMware esxi 5.5装机方案
  • 原文地址:https://www.cnblogs.com/formyjava/p/4166313.html
Copyright © 2011-2022 走看看