<!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>

转载于:https://www.cnblogs.com/yaowen/p/7224762.html

angularjs1-2,作用域、代码压缩相关推荐

  1. Android Studio 3.3 Beta提供了新的Android代码压缩器R8

    摘要: 在将D8作为其新的Dalvik编译器之后,谷歌已经开始研发新的代码压缩器R8,在Android Studio 3.3 beta版本上它已经可以使用了.R8承诺用更少的时间交付更小的APK文件. ...

  2. webpack --- 发布环境的配置 代码压缩 代码分类

    说明 源代码 本篇主要对发布环境的配置说明 前面2点是对webpack的一个复习. 第3点开始,逐步配置部署代码 1. Webpack发布的策略 2.1 在实际开发中,一般会有两套方案: 开发期间的项 ...

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

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

  4. python 全局变量使用报错没有定义_Python变量作用域代码解析

    本篇文章小编给大家分享一下Python变量作用域代码解析,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. 特点 python的作用域是静态的,在源代码中 ...

  5. 压缩html页面 seo,WordPress前端html代码压缩优化方法

    为了优化网站的访问速度,对网页进行压缩是非常不错的一条方法.压缩页面减少了页面的体积提升了访问速度. 部署功能代码 //压缩html代码 function wp_compress_html(){ fu ...

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

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

  7. Yii --EClientScript 扩展,css,js文件代码压缩合并加载

    扩展插件下载地址,解压后复制到/protected/vendor/ https://github.com/muayyad-alsadi/yii-EClientScript main配置文件配置插件,c ...

  8. 在线CSS代码压缩美化工具

    在线CSS代码压缩美化工具 在线CSS代码压缩美化工具 在线CSS代码压缩.格式化工具.可以删除注释 在线CSS代码压缩.格式化工具.可以删除注释 https://tooltt.com/css/

  9. android 万能混淆文件,Android ProGuard 代码压缩混淆与打包优化

    为什么要启动ProGuard(所有试验都在AS 环境) 代码压缩通过 ProGuard 提供,ProGuard 会检测和移除封装应用中未使用的类.字段.方法和属性, 包括自带代码库中的未使用项(这使其 ...

  10. web前端学习中CSS,JS代码压缩

    web前端要学习的知识有很多,前端基础要学习三个部分:HTML,CSS,JavaScript(简称JS),因此首先明确三个概念:HTML负责结构,网页想要表达的内容由html书写. CSS负责样式,网 ...

最新文章

  1. 加载多瓦片地图_手把手教 | 网络时空大数据爬取与分析DAS系统(瓦片地图获取)...
  2. win7 安装wget
  3. 共建网络安全堤坝,守住网络安全底线
  4. java课程设计总结与思考,你掌握了多少?
  5. poj 1873 枚举+凸包
  6. 网络数据的XML解析
  7. 项目:网站架构,集群
  8. final、finally、finalize的区别
  9. 【业务知识】档案工作流程
  10. 怎样把颜色转换为字符串
  11. linux 查询替换文件内容吗,Linux 下查询文件的方法 替换文件内容
  12. 某省HW中遇到的提权
  13. mongodb副本集搭建
  14. php rsa加密乱码_php RSA加解密
  15. 图像检索(一)--综述
  16. fopen php 读取_PHP fopen读取url内容
  17. webpack 3 零基础入门教程 #16 - 使用 ProvidePlugin 插件来处理像 jQuery 这样的第三方包...
  18. 360桌面隐藏应用 android代码,360手机桌面上的隐藏应用怎么设置?
  19. 怎么给照片加眼镜(二):3D眼镜模型合成法
  20. Python基础——修改Python字典中的key(键)

热门文章

  1. 将数据库表中的数据读出以xml的形式下载到手机端
  2. 数据分类是否一定要求样本均衡
  3. 基于论辩图谱的互动论点对识别
  4. 百度工程师带来干货分享,助你转型AI应用工程师!
  5. 【文本摘要】BottleSum——文本摘要论文系列解读
  6. 6.2 API : RandomForestClassifier与RandomForestRegressor
  7. LeetCode学习记录(4-6)
  8. 每周荐书:微服务、SQL调优、机器学习(评论送书)
  9. Effective C++:改善程序与设计的55个具体做法:第3版 评注者序
  10. 用JavaScript编写COM组件的步骤