$window Service:

AngularJs includes $window service which refers to the browser window object.

In the JavaScript, window is a global object which includes many built-in methods like alert(), prompt() etc.

The $window service is a wrapper around window object, so that it will be easy to override, remove or mocked for testing. It is recommended to use $window service in AngularJS instead of global window object directly.

Example: $window

<!DOCTYPE html>
    <script src="~/Scripts/angular.js"></script>
<body ng-app="myApp" ng-controller="myController">
    <button ng-click="DisplayAlert('Hello World!')">Display Alert</button>
    <button ng-click="DisplayPrompt()">Display Prompt</button>
        var myApp = angular.module('myApp', []);

        myApp.controller("myController", function ($scope, $window) {

            $scope.DisplayAlert = function (message) {

            $scope.DisplayPrompt = function () {
                var name = $window.prompt('Enter Your Name');
                $window.alert('Hello ' + name);