Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AngularJS controller with output

  • ng-controller

  • module

  • $scope

  • Separate JavaScript from the HTML

  • ng-controller

  • angular.module(name, [dependencies])

  • .controller

  • $scope


<script src="angular.min.js"></script>
<script src="hello_world_controller.js"></script>
<div ng-app="HelloWorldApp">
    <div ng-controller="HelloWorldController">
        <h1>{{greeting}}</h1>
    </div>
</div>
angular.module('HelloWorldApp', [])
   .controller('HelloWorldController', ['$scope', function($scope) {
       $scope.greeting = "Hello World";
}]);