1、创建module

//第一个参数是模块的名称
var head=angular.module('headApp',[]);
head.controller("User",["$scope",function($scope){
$scope.UserName="admin";
$scope.LoginTime=new Date().toString();
}]);

2、创建module且此模块要依赖其它module

// 创建module且此模块要依赖其它模块
// 第二个参数是依赖的模块名称,如果不依赖任何模块要传空数组[]。
// 注意:如果第二个参数不传,则是获取当前名称的模块
var my=angular.module('myApp',["headApp"]);
my.controller("Content",["$scope",function($scope){
$scope.Text="this is a test page";
}]);

3、不同module有相同的controller时的调用方式

//如果当前模块和依赖具有相同的controller,则会调用当前模块的controller。
//当前模块没有此controller时,才会调用依赖模块中的controller
//可以对下面的controller代码进行注释(或去掉注释),看页面的效果
// my.controller("User",["$scope",function($scope){
// $scope.UserName="admin123";
// $scope.LoginTime="2015-7-25";
// }]);

  

demo代码如下:

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>模块化</title>
<script type="text/javascript" src="angular.js"></script>
</head>
<body>
<div ng-controller="User">
<p>用户名:{{UserName}}</p>
<p>登录时间:{{LoginTime}}</p>
</div>
<div ng-controller="Content">
<p>{{Text}}</p>
</div>
</body>
</html>
<script type="text/javascript">
//创建module
//第一个参数是模块的名称
var head=angular.module('headApp',[]);
head.controller("User",["$scope",function($scope){
$scope.UserName="admin";
$scope.LoginTime=new Date().toString();
}]); // 创建module且此模块要依赖其它模块
// 第二个参数是依赖的模块名称,如果不依赖任何模块要传空数组[]。
// 注意:如果第二个参数不传,则是获取当前名称的模块
var my=angular.module('myApp',["headApp"]);
my.controller("Content",["$scope",function($scope){
$scope.Text="this is a test page";
}]); //不同module有相同的controller时的调用方式
//如果当前模块和依赖具有相同的controller,则会调用当前模块的controller。
//当前模块没有此controller时,才会调用依赖模块中的controller
//可以对下面的controller代码进行注释(或去掉注释),看页面的效果
// my.controller("User",["$scope",function($scope){
// $scope.UserName="admin123";
// $scope.LoginTime="2015-7-25";
// }]);
</script>

  

猛戳代码测试地址

angularjs——module的更多相关文章

  1. AngularJS -- Module (模块)

    点击查看AngularJS系列目录 转载请注明出处:http://www.cnblogs.com/leosx/ 什么是AngularJS的模块 我们所说的模块,是你的AngularJS应用程序的一个组 ...

  2. Angularjs Module类的介绍及模块化依赖

    后面的学习我们会遵循一个控制器管理一个视图,一个路由对应一个视图的单一原则,所以再不会将controller控制器代码直接写到 index.html 中. 我们会应用到angular.js中强大的模块 ...

  3. AngularJS-01.AngularJS,Module,Controller,scope

    1.AngularJS 一个构建动态Web应用程序的结构化框架. 基于JavaScript的MVC框架.(  MVC ---- Model(模型).View(视图).Controller(控制器) ) ...

  4. angularJS module里的'服务'

    首先,为了举栗子,先写好如下的模型,控制器,html: html: <!DOCTYPE html> <html ng-app="serviceApp"> & ...

  5. AngularJS 30分钟快速入门【译】

    引用自:http://www.revillweb.com/tutorials/angularjs-in-30-minutes-angularjs-tutorial/,翻译如下: 简介 我三年前开始使用 ...

  6. Integrating AngularJS with RequireJS

    Integrating AngularJS with RequireJS When I first started developing with AngularJS keeping my contr ...

  7. 4.了解AngularJS模块和依赖注入

    1.模块和依赖注入概述 1.了解模块 AngularJS模块是一种容器,把代码隔离并组织成简洁,整齐,可复用的块. 模块本身不提供直接的功能:包含其他提供功能的对象的实例:控制器,过滤器,服务,动画 ...

  8. Make AngularJS $http service behave like jQuery.ajax()(转)

    There is much confusion among newcomers to AngularJS as to why the $http service shorthand functions ...

  9. AngularJS基础总结

    w3shools    angularjs教程  wiki   <AngularJS权威教程> Introduction AngularJS is a JavaScript framewo ...

随机推荐

  1. vsftpd 访问 权限控制

    vsftpd 重启命令 service vsftpd  start|restart|stop vsftpd 关于权限控制,有两个文件分别设置,都会起作用 /etc/vsftpd/user_list / ...

  2. python实现tailf

    # -*- coding:utf-8 -*- ''' Created on 2016年10月28日 @author: zhangsongbin ''' import time class file_r ...

  3. C# 文件创建时间,修改时间

    System.IO.FileInfo fi = new System.IO.FileInfo(@"D:\site\EKECMS\skin\Grey\default#.html"); ...

  4. The 500 Most Commonly Used Words in the English Language

    Based on the combined results of British English, American English and Australian English surveys of ...

  5. 实现Rsync同步Nginx前端配置

    近期,由于我们的阿里前端服务器频频受到恶意的流量攻击,导致前端NGINX进入黑洞而无法正常访问公司网站. 按之前的预计方法,采用加速乐及备用全配置前端的作法,将恶意短时流量攻击的损失时间降到最短.现将 ...

  6. 开启Apache mod_rewrite模块(解决404 Not Found)

    网站搭建完成了,进入登录界面就是访问不了. 原因大概是没有开启Apache mod_rewrite模块,或者没有配置完全. 步骤1: 启用mod_rewrite模块 在conf目录的httpd.con ...

  7. COJ 0802 非传统题(二)

    (颓了这么多天是时候干点正事了QAQ) 非传统题(二) 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 还是很久很久以前,chx ...

  8. Linux企业级项目实践之网络爬虫(28)——爬虫socket处理

    Socket是进程之间交换数据的机制.这些进程即可以是同一台机器上的,也可以是通过网络连接起来的不同机器.一旦一个Socket连接建立,那么数据就能够双向传输,直到其中一端关闭连接. 通常,请求数据的 ...

  9. codevs1033 蚯蚓的游戏问题

    题目描述 Description 在一块梯形田地上,一群蚯蚓在做收集食物游戏.蚯蚓们把梯形田地上的食物堆积整理如下: a(1,1)  a(1,2)…a(1,m) a(2,1)  a(2,2)  a(2 ...

  10. HDU_1016——素环问题DFS

    Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ... ...