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.
        
        
        
        

  • 相关阅读:
    架构师考试回顾
    精通 WPF UI Virtualization
    疑难杂症之Web客户端无法登录
    CDTray, 打开,关闭光驱的系统托盘程序
    原来Queryable是这样实现的..
    jQuery.Excel, 使用Ctrl+方向键/Home/End在input表格中移动
    nGoodPersonCards++
    C#数据库数据导入导出系列之三 数据库导出到Excel下
    调用webservice时提示对操作的回复消息正文进行反序列化时出错&&Web service 超过了最大请求长度
    ASP.NET网络映射驱动器无权限访问的解决方案(转)
  • 原文地址:https://www.cnblogs.com/formyjava/p/4166313.html
Copyright © 2011-2022 走看看