AngularJS

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="~/Scripts/angular.min.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='张三';
          }]);       
app.controller(
'secondController',['$scope','$rootScope',function($scope,$rootScope){ $scope.name='李四'; $rootScope.age='30'; }]); //只对全局作用域生效,可以用来注册全局的东西 app.run(['$rootScope',function($rootScope){ $rootScope.sex='男'; }]); console.log(app); </script> </body> </html>
原文地址:https://www.cnblogs.com/MarchThree/p/5353234.html