AngularJS的“.module(“modulename", […])"中的方括号是什么意思 [英] What is the meaning of the square brackets in “.module("modulename", […])” of AngularJS

查看:26
本文介绍了AngularJS的“.module(“modulename", […])"中的方括号是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚看到了一个示例 AngularJS 中的路由.我想知道依赖 'ngRoute' 和模块 mainApp 之间的关系,在 Synatx var mainApp = angular.module("mainApp", ['ngRoute']);.

I just saw an example of routing in AngularJS. I would like to know the relation ship between dependency 'ngRoute' and module mainApp, in synatx var mainApp = angular.module("mainApp", ['ngRoute']);.

以前我见过在模块声明中使用空方括号的例子.

Previously I've seen examples with empty square brackets in module declaration.

以下是代码的整个上下文:

Below is the whole context of code:

var mainApp = angular.module("mainApp", ['ngRoute']);

  mainApp.config(['$routeProvider',
     function($routeProvider) {
        $routeProvider.
           when('/addStudent', {
              templateUrl: 'addStudent.htm',
              controller: 'AddStudentController'
           }).
           when('/viewStudents', {
              templateUrl: 'viewStudents.htm',
              controller: 'ViewStudentsController'
           }).
           otherwise({
              redirectTo: '/addStudent'
           });
     }]);

推荐答案

[...] 定义一个数组

在有角的情况下.

mainApp 是主模块(主数组),ngRoute 是子模块(类似于对象数组).

mainApp is a main module( main array) and ngRoute is a sub module(like array of object).

样本是

var ngRoute=[];//{}

var mainApp=[ngRoute];// now the `mainApp` includes the `ngRoute`

这篇关于AngularJS的“.module(“modulename", […])"中的方括号是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆