angularjs——module
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的更多相关文章
- AngularJS -- Module (模块)
点击查看AngularJS系列目录 转载请注明出处:http://www.cnblogs.com/leosx/ 什么是AngularJS的模块 我们所说的模块,是你的AngularJS应用程序的一个组 ...
- Angularjs Module类的介绍及模块化依赖
后面的学习我们会遵循一个控制器管理一个视图,一个路由对应一个视图的单一原则,所以再不会将controller控制器代码直接写到 index.html 中. 我们会应用到angular.js中强大的模块 ...
- AngularJS-01.AngularJS,Module,Controller,scope
1.AngularJS 一个构建动态Web应用程序的结构化框架. 基于JavaScript的MVC框架.( MVC ---- Model(模型).View(视图).Controller(控制器) ) ...
- angularJS module里的'服务'
首先,为了举栗子,先写好如下的模型,控制器,html: html: <!DOCTYPE html> <html ng-app="serviceApp"> & ...
- AngularJS 30分钟快速入门【译】
引用自:http://www.revillweb.com/tutorials/angularjs-in-30-minutes-angularjs-tutorial/,翻译如下: 简介 我三年前开始使用 ...
- Integrating AngularJS with RequireJS
Integrating AngularJS with RequireJS When I first started developing with AngularJS keeping my contr ...
- 4.了解AngularJS模块和依赖注入
1.模块和依赖注入概述 1.了解模块 AngularJS模块是一种容器,把代码隔离并组织成简洁,整齐,可复用的块. 模块本身不提供直接的功能:包含其他提供功能的对象的实例:控制器,过滤器,服务,动画 ...
- Make AngularJS $http service behave like jQuery.ajax()(转)
There is much confusion among newcomers to AngularJS as to why the $http service shorthand functions ...
- AngularJS基础总结
w3shools angularjs教程 wiki <AngularJS权威教程> Introduction AngularJS is a JavaScript framewo ...
随机推荐
- iOS开发——C篇&文件操作
今天开始C语言中的重点难点就基本上技术忘了,但是还有最后一个知识点不得不提,那就是文件操作. 我们都知道,我们每天都在使用电脑,手机,或者其他电子或者移动设备,其实我们在使用的时候每时每刻都在执行文件 ...
- 针对苹果最新审核要求为应用兼容IPv6-备用
在WWDC2015上苹果宣布iOS9将支持纯IPv6的网络服务.2016年初开始所有提交到App Store的应用必须支持IPv6.为确保现有的应用是兼容的,我们需要注意下面几点. 不建议使用底层的网 ...
- SVM及其对偶
引自 http://my.oschina.net/wangguolongnk/blog/111349 1. 支持向量机的目的是什么? 对于用于分类的支持向量机来说,给定一个包含正例和反例(正样本点和负 ...
- 简单DOS命令实现局域网Windows远程关机
1秒内重启局域网内计算机名为ppgsvr-pc的用户电脑shutdown -r -m \\ComputerName -t 1 1秒内关闭局域网内ppgsvr用户电脑shutdown -s -m \\C ...
- css3 之表格隔行分色显示
<html> <head> <title></title> <style type="text/css"> table{ ...
- PCB设计备忘录
在PCB设计过程中,常常有很多细节只有在实践中才能体会到其重要性,本人记性不好,索性把相关的注意点记录下来,也顺便希望能够给读者朋友们一些帮助. 接插件以及连接器比较常用的针脚之间间距有2.54mm/ ...
- USBSpirit(USB精灵)更新到1.2.300.105
USBSpirit(USB精灵)是CopyU!的内核引擎,CopyU!的主要功能均由该引擎提供,此次更新主要内容如下:(版本号:1.2.300.105) 1.[修复]:修复了几处引擎的资源泄露问题,提 ...
- 8.2.1.8 IS NULL Optimization NULL 优化:
8.2.1.8 IS NULL Optimization NULL 优化: Oracle 对待null值: SQL> create table t100(id int,name char(10) ...
- cocos2d-x 找不到资源文件问题
问题描述: 在项目中引用到了图片,但是运行时报错: Unhandled exception at 0x001049DE in hello.exe: 0xC0000005: Access violati ...
- leetcode-Consecutive numbers
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...