<body ng-app> <div ng-controller="PersonCtrl"> <p>{{person.name}}</p> <p>{{sex}}</p> </div> <p>{{person.name}}</p> <p>{{sex}}</p> <script> function PersonCtrl($scope, $rootScope) { $scope.person = { 'name': 'Zhang', 'age': 23 } $rootScope.sex = '男'; } </script> </body>
<body ng-app> <div ng-controller="PersonCtrl1"> <p>{{name}}</p> <p>{{age}}</p> <div ng-controller="PersonCtrl2"> <p>{{name}}</p> <p>{{age}}</p> </div> </div> <script> function PersonCtrl1($scope) { $scope.name = 'Handsome'; $scope.age = 22; } function PersonCtrl2($scope) { $scope.name = 'Zhang'; } </script> </body>