angular.module()

    xiaoxiao2021-03-26  21

    angular.module()创建、获取、注册angular中的模块

    The angular.module() is a global place for creating, registering and retrieving Angular modules.When passed two or more arguments, a new module is created. If passed only one argument, an existing module (the name passed as the first argument to module) is retrieved。

    // 传递参数不止一个,代表新建模块;空数组代表该模块不依赖其他模块 var createModule = angular.module("myModule", []); // 只有一个参数(模块名),代表获取模块 // 如果模块不存在,angular框架会抛异常 var getModule = angular.module("myModule"); // true,都是同一个模块 alert(createModule == getModule); 该函数既可以创建新的模块,也可以获取已有模块,是创建还是获取,通过参数的个数来区分。

    angular.module(name, [requires], [configFn]);

    name:字符串类型,代表模块的名称;

    requires:字符串的数组,代表该模块依赖的其他模块列表,如果不依赖其他模块,用空数组即可;

    configFn:用来对该模块进行一些配置。

    现在我们知道如何创建、获取模块了,那么模块究竟是什么呢?官方的Developer Guide上只有一句话:You can think of a module as a container for the different parts of your app – controllers, services, filters, directives, etc.

    转载请注明原文地址: https://ju.6miu.com/read-660982.html

    最新回复(0)