angular js $scope 作用域
2015-08-04 11:36
711 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.bootcss.com/angular.js/1.4.3/angular.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="MyController">
1.这是控制器里面
<h1>{{ person }}</h1>
and their name:
<h2>{{ person.name }}</h2>
</div>
2.这是控制器外面 myApp里面
<h1>{{ person }}</h1>
and their name:
<h2>{{ person.name }}</h2>
</div>
3.这是myApp外面
<h1>{{ person }}</h1>
and their name:
<h2>{{ person.name }}</h2>
<script>
angular.module('myApp', [
'myApp.services',
'myApp.directives',
'myApp.filters',
'myApp.controllers'
]);
angular.module('myApp.services', []).value('version', '0.0.1');
angular.module('myApp.directives', []);
angular.module('myApp.filters', []);
angular.module('myApp.controllers', [])
.controller('MyController', function($scope) {
$scope.person = {
name: 'Ari Lerner'
};
});
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.bootcss.com/angular.js/1.4.3/angular.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="MyController">
1.这是控制器里面
<h1>{{ person }}</h1>
and their name:
<h2>{{ person.name }}</h2>
</div>
2.这是控制器外面 myApp里面
<h1>{{ person }}</h1>
and their name:
<h2>{{ person.name }}</h2>
</div>
3.这是myApp外面
<h1>{{ person }}</h1>
and their name:
<h2>{{ person.name }}</h2>
<script>
angular.module('myApp', [
'myApp.services',
'myApp.directives',
'myApp.filters',
'myApp.controllers'
]);
angular.module('myApp.services', []).value('version', '0.0.1');
angular.module('myApp.directives', []);
angular.module('myApp.filters', []);
angular.module('myApp.controllers', [])
.controller('MyController', function($scope) {
$scope.person = {
name: 'Ari Lerner'
};
});
</script>
</body>
</html>
相关文章推荐
- js倒计时
- jsp页面EL表达式不被解析问题总结
- 《JS设计模式笔记》 4,桥接模式
- js 循环
- [JSTL笔记]—c标签
- js的本地存储localstorge
- javascript+HTML5的canvas实现七夕情人节3D玫瑰花效果代码
- 块排列并放大
- 下拉树列表菜单选择器(2)
- 基于js的地理数据的几何运算turfjs
- 判断js是否被禁用
- javascript控制图片播放的实现代码
- JS 日期时间比较 值类型和引用类型
- Jsoup学习笔记10:Saz2Csv解析器
- iscroll.js--滚动加载实例
- 两种JS实现屏蔽鼠标右键的方法
- JS学习2--关于预解释
- 深入理解javascript之函数
- JS中cookie的基本使用
- js判断出两个字符串最大子串的函数