<!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,作用域、代码压缩的更多相关文章

  1. UglifyJS--javascript代码压缩使用指南{转}

    在线测试地址 http://lisperator.net/uglifyjs/下面都是基于linux系统的安装使用.UglifyJS是遵循了CommonJS规范写成的,可以在支持CommonJS模块系统 ...

  2. Asp.Net MVC 页面代码压缩筛选器-自定义删除无效内容

    Asp.Net MVC 页面代码压缩筛选器 首先定义以下筛选器,用于代码压缩. /*页面压缩 筛选器*/ public class WhiteSpaceFilter : Stream { privat ...

  3. 使用Gulp进行代码压缩的步骤以及配置

    一.安装步骤 1.首先确定是否安装了node.js,如果未安装,请先安装node.js: 2.确定是否安装了包管理工具npm,如未安装请安装:npm install npm -g: 3.安装gulp: ...

  4. 使用gulp进行代码压缩

    gulp是一个很不错的前端自动化工具,可以帮我们完成一些重复性操作,比如html.css和js代码的压缩.合并.混淆等,虽然这些操作可以通过一些在线工具帮我们实现,但不断重复地复制粘贴肯定比不上一句命 ...

  5. fis代码压缩

    Fis代码压缩步骤 1,安装fis(http://fis.baidu.com/fis3/docs/beginning/install.html) fis安装支持的node版本:0.8x,0.10x,0 ...

  6. 如何利用Grunt生成对应的Source Map文件,线上代码压缩使用chrome浏览器便于调式

    如何利用Grunt生成对应的Source Map文件,线上代码压缩使用chrome浏览器便于调式 首先我们来说说为何要生成sourceMap文件呢?简单的说,sourceMap是为了压缩后的代码调式提 ...

  7. apicloud代码压缩和全局加密

    首先说代码压缩,因为没什么用,就先说它了.代码压缩后,apicloud里面的css和js文件里面的空格呀回车呀都去掉了,就是文件小了,所有代码显示为一行了.这些代码的变量没有重命名,我们知道jquer ...

  8. HTML-DEV-ToolLink(常用的在线字符串编解码、代码压缩、美化、JSON格式化、正则表达式、时间转换工具、二维码生成与解码等工具,支持在线搜索和Chrome插件。)

    HTML-DEV-ToolLink:https://github.com/easonjim/HTML-DEV-ToolLink 常用的在线字符串编解码.代码压缩.美化.JSON格式化.正则表达式.时间 ...

  9. php代码压缩

    php代码压缩,除可以使用token_get_all进行压缩之外,还可以使用系统自带的函数   php_strip_whitespace (PHP 5) php_strip_whitespace — ...

随机推荐

  1. 09-JavaScript高级

    今日知识 1. Dom(文档对象模型) 2. Bom(浏览器对象模型) 3. 总结 Dom 1. 获取id为div1的元素对象. * var result=document.getElementByI ...

  2. [Luogu1273] 有线电视网

    [Luogu1273] 有线电视网 题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端,其他中转站为该树 ...

  3. B - Soldier and Bananas

    Problem description A soldier wants to buy w bananas in the shop. He has to pay k dollars for the fi ...

  4. C - Valera and Fruits

    Problem description Valera loves his garden, where n fruit trees grow. This year he will enjoy a gre ...

  5. 带中横线的日期格式在iOS手机系统上 转换时间戳NaN问题

    类似于 '2019-04-01 14:13:00' 这样的日期格式转换时间戳在iOS手机上是无法转换的,需要先处理日期格式成 '2019/04/01 14:13:00' var str = '2019 ...

  6. 解决生成主键 id重复的解决办法

    作者:董春秋链接:https://www.zhihu.com/question/30674667/answer/49082988来源:知乎著作权归作者所有,转载请联系作者获得授权. 全局id生成器.我 ...

  7. Aspose.Words进行Word替换(插入图片和水印)

    由于最近一直在忙着做着Word打印模板的一些工作,就整理一些Asponse.Words对Word文档进行操作的资料. using System; using System.Collections.Ge ...

  8. 给WordPress的TinyMCE Advanced编辑器加上中文字体

    为TinyMCE编辑器增加中文字体并不复杂,只需要将将如下代码加到当前主题的functions.php文件中最后一个?>的前面即可: 不要忘记保存,然后更新一遍浏览器即可 //为TinyMCE编 ...

  9. 基于Intent实现Activity与Activity之间的数据传递,实现二个Activity的跳转功能

    在讲参数传递之前,先讲下intent的定义: Intent intent = new Intent(MainActivity.this,SecondActivity.class);  //这是显式定义 ...

  10. vue首次进入微信没有标题问题

    首先实在路由改变的时候可以有标题的    首次进入路由不显示标题,查到很多,最有解决可以自定义标签, 后者引入一个包vue-wechat-title,我就是用的后者,前面的没有式过 上地址  http ...