AngularJS $scope

$scope对象就是一个普通的JavaScript对象,我们可以在其上随意修改或添加属性。

$scope的所有属性,都可以自动被视图访问到。

<!doctype html>



<html ng-app="myAppModule">

<head>

  <title>Controller</title>

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"></script>

</head>


<body>

  <div ng-controller="MyController">

    <h1>{{ name.FirstName }}</h1>

  </div>

  <script>


    var app = angular.module('myAppModule', []);

    app.controller('MyController', function($scope) {

      $scope.name = {

        FirstName: "FirstName"

      };


    });

  </script>

</body>

</html>

登录后才可评论.