angular是非常火的H5架包,现在就简单分享一个anjular 模块控制器分离的简单例子
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/angular-1.3.0.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
{{name}}
{{age}}
<div ng-controller="secondController">
{{name}}
{{age}}
{{sex}}
</div>
</div>
{{sex}}
</div>
<script type="text/javascript">
var app = angular.module("myApp",[]);
app.controller('firstController',['$scope',function($scope){
$scope.name='zhangsan';
}]);
app.controller('secondController',['$scope','$rootScope',function($scope,$rootScope){
$scope.name='lisi';
$rootScope.age = '30';
}]);
</script>
</body>
</html>