Chapter 19, $window and $document (Pro AngularJS)

by js_test

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<body ng-app="exampleApp" ng-controller="defaultCtrl" class="well">
    <button class="btn btn-primary">Click Me</button>
</body>

JavaScript

var myApp = angular.module("exampleApp", []);

myApp.controller("defaultCtrl", function ($scope, $window, $document) {
    $document.find("button").on("click", function (event) {
        $window.alert(event.target.innerText);
    });
});