标签:
<body ng-app="myApp">
<p>多个控制器</p>
<div ng-controller="Ctrl1">
<p>{{greeting.text}}, Angular</p>
</div>
<div ng-controller="Ctrl2">
<p>{{greeting.text}}, Ctrl2</p>
<p>{{program.text}}, program</p>
</div>
<script src="js/angular-1.3.0.js"></script>
<script>
/*
function Ctrl1($scope, $rootScope){
$scope.greeting = { text:"Hello" }
$rootScope.program = { text:"angularjs" };
}
function Ctrl2($scope){
$scope.greeting = {text:"Good morning"};
}
*/
var app = angular.module("myApp", []);
app.controller("Ctrl1", function($scope, $rootScope){
$rootScope.greeting = { text:"Hello" };
});
app.controller("Ctrl2", function($scope){
$scope.program = { text:"text2" };
});
</script>
</body>
标签:
原文地址:http://www.cnblogs.com/lianfu/p/4996807.html