formations/javascript/angular/scope-2.md

679 B

.cadoles-slide-title[L'objet $scope (2/4)]

Contrôleurs et héritage prototypal des $scope

<html>
  <body ng-app="myApp">

  <div ng-controller="ParentCtrl">
    {{parentProp}} <!-- "Foo" -->
    <div ng-controller="ChildCtrl">
*     {{parentProp}} <!-- "Foo" -->
      {{childProp}} <!-- "Bar" -->
    </div>
  </div>

  <script src="angular.js"></script>
  <script>
    var myApp = angular.module('myApp', []);

    myApp.controller('ParentCtrl', ['$scope', function($scope) {
*     $scope.parentProp = "Foo";
    }]);

    myApp.controller('ChildCtrl', ['$scope', function($scope) {
*     $scope.childProp = "Bar";
    }]);

  </script>
  </body>
</html>