angularjs1-2,作用域、代码压缩
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
{{name}}
{{age}}
{{sex}}
<div ng-controller="secondController">
{{name}}
{{age}}
{{sex}} //secondController作用域先在自己作用域查找,然后再去firstController查找,firstController也没有就去rootScope查找。
</div>
</div>
{{name}}
{{age}}
{{sex}}
</div>
<script type="text/javascript">
var app = angular.module("myApp", []);
//代码压缩不会把字符串压缩,只会把函数的形参压缩,因此前面写全,后面可以简写。
app.controller('firstController',['$scope',function($s){
$s.name='张三2';
}]);
app.controller('secondController',['$scope','$rootScope',function($s,$r){
$s.name='李四';
$r.age='30';
}]);
app.run(['$rootScope',function($r){
$r.name='ggggg';
$r.age='3333';
$r.sex='男';
}]);
console.log(app);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
{{name}}
{{age}}
</div>
<div ng-controller="secondController">
{{name}}
{{age}}
</div>
</div>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller('firstController',function($scope){
$scope.name='张三';
});
app.controller('secondController',function($scope,$rootScope){
// $scope.name='李四';
$rootScope.age='30';
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="../../angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
{{name}}
</div>
<div ng-controller="secondController">
{{name}}
</div>
</div>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller('firstController',function($scope){//scope的作用域是controller作用域
$scope.name='张三';
});
app.controller('secondController',function($scope){
$scope.name='李四';
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="../../angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
姓名: {{name}} <br>
年龄:{{age}}
</div>
<div ng-controller="secondController">
姓名:{{name}}
年龄:{{age}}
</div>
</div>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller('firstController',function($scope,$rootScope){//rootScope作用域是ng-app作用域
$scope.name='张三';
$rootScope.age='30';
});
app.controller('secondController',function($scope){
$scope.name='李四';
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="../angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
{{name}}
{{age}}
{{sex}}
<div ng-controller="secondController">
{{name}}
{{age}}
{{sex}} //里层的作用域会去找外层的作用域
</div>
</div>
</div>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller('firstController',function($scope){
$scope.name='张三1';
$scope.age='40';
});
app.controller('secondController',function($scope){
$scope.name='李四';
$scope.sex='男';
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="../angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div>
<p>{{name}}</p>
</div>
</div>
<script type="text/javascript">
var m1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope',function($scope){
$scope.name = 'hello111';
}]);
m1.controller('Bbb',['$scope',function($scope){
$scope.name = 'hi';
}]);
m1.run(['$rootScope',function($rootScope){
//run方法初始化全局数据,只对全局作用域起作用。
$rootScope.name = 'hello';
}]);
console.log( m1 );
</script>
</body>
</html>
angularjs1-2,作用域、代码压缩的更多相关文章
- UglifyJS--javascript代码压缩使用指南{转}
在线测试地址 http://lisperator.net/uglifyjs/下面都是基于linux系统的安装使用.UglifyJS是遵循了CommonJS规范写成的,可以在支持CommonJS模块系统 ...
- Asp.Net MVC 页面代码压缩筛选器-自定义删除无效内容
Asp.Net MVC 页面代码压缩筛选器 首先定义以下筛选器,用于代码压缩. /*页面压缩 筛选器*/ public class WhiteSpaceFilter : Stream { privat ...
- 使用Gulp进行代码压缩的步骤以及配置
一.安装步骤 1.首先确定是否安装了node.js,如果未安装,请先安装node.js: 2.确定是否安装了包管理工具npm,如未安装请安装:npm install npm -g: 3.安装gulp: ...
- 使用gulp进行代码压缩
gulp是一个很不错的前端自动化工具,可以帮我们完成一些重复性操作,比如html.css和js代码的压缩.合并.混淆等,虽然这些操作可以通过一些在线工具帮我们实现,但不断重复地复制粘贴肯定比不上一句命 ...
- fis代码压缩
Fis代码压缩步骤 1,安装fis(http://fis.baidu.com/fis3/docs/beginning/install.html) fis安装支持的node版本:0.8x,0.10x,0 ...
- 如何利用Grunt生成对应的Source Map文件,线上代码压缩使用chrome浏览器便于调式
如何利用Grunt生成对应的Source Map文件,线上代码压缩使用chrome浏览器便于调式 首先我们来说说为何要生成sourceMap文件呢?简单的说,sourceMap是为了压缩后的代码调式提 ...
- apicloud代码压缩和全局加密
首先说代码压缩,因为没什么用,就先说它了.代码压缩后,apicloud里面的css和js文件里面的空格呀回车呀都去掉了,就是文件小了,所有代码显示为一行了.这些代码的变量没有重命名,我们知道jquer ...
- HTML-DEV-ToolLink(常用的在线字符串编解码、代码压缩、美化、JSON格式化、正则表达式、时间转换工具、二维码生成与解码等工具,支持在线搜索和Chrome插件。)
HTML-DEV-ToolLink:https://github.com/easonjim/HTML-DEV-ToolLink 常用的在线字符串编解码.代码压缩.美化.JSON格式化.正则表达式.时间 ...
- php代码压缩
php代码压缩,除可以使用token_get_all进行压缩之外,还可以使用系统自带的函数 php_strip_whitespace (PHP 5) php_strip_whitespace — ...
随机推荐
- arg max f(x) 含义
y = f(x) 是一般常见的函数式,如果给定一个x值,f(x)函数式会赋一个值給y. y = max f(x) 代表:y 是f(x)函式所有的值中最大的output. y = arg max f(x ...
- C#缓存
最近在学习缓存的知识,博客园中的 缓存资料 觉得信息不错值得学习
- android随手记
Linearlayout: gravity:本元素中所有子元素的重力方向 layout_gravity:本元素对于父元素的重力方向 自定义权限:http://www.cnblogs.com/i ...
- 修改ElementUI源码
1.克隆ElementUI官方仓库代码到本地 https://github.com/ElemeFE/element 2.在cmd命令行安装依赖 1)找到代码文件夹 cd element 2)npm ...
- outlook 2010 搜索不到邮件
打开outlook 2010 文件, 选项, 加载项, 转到 windows search eamil indexer(打勾) 关闭outlook 控制面板, 索引选项, 高级, 重建索引
- Kattis -Safe Passage(撑伞问题)
Safe Passage Photo by Ian Burt A group of friends snuck away from their school campus, but now they ...
- 查看Linux系统版本信息的几种方法
一.查看Linux内核版本命令(两种方法): 1.cat /proc/version 2.uname -a 二.查看Linux系统版本的命令(3种方法): 1.lsb_release -a,即可列出所 ...
- Angular之constructor和ngOnInit差异及适用场景(转)
原始地址:https://blog.csdn.net/u010730126/article/details/64486997 Angular中根据适用场景定义了很多生命周期函数,其本质上是事件的响应函 ...
- nodejs 使用crypto实现sha256\md5加密
var crypto = require('crypto'); var hash = crypto.createHash('sha256');// sha256或者md5 hash.update('1 ...
- KMP算法(推导方法及模板)
介绍 克努斯-莫里斯-普拉特算法Knuth-Morris-Pratt字符串查找算法(简称为KMP算法)可在一个主文本字符串S内查找一个词W的出现位置.此算法通过运用对这个词在不匹配时本身就包含足够的信 ...