您的位置:首页 > Web前端 > JavaScript

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: