AngularJS $document Service (original) (raw)
Last Updated : 23 Jan, 2023
In AngularJS, a service is a function or object that is available for dependency injection (DI) in an AngularJS app. Services are typically used to encapsulate and reuse business logic and other app functionality that is not directly related to the presentation of data in the app.
The $document service in AngularJS is a wrapper around the browser's document object, which represents the HTML document that is being displayed in the browser. It provides a convenient way to manipulate the document object within an AngularJS application. The $document service can be used to get a reference to DOM elements, bind event listeners to the document object, and perform other common tasks with the document object.
Syntax:
angular.module('myModule', []) .controller('MyController', function($scope, $document) { // Use the $document service here });
The $document service in AngularJS does not take any arguments. It is a wrapper around the browser's document object, and it provides a convenient way to manipulate the document object within an AngularJS application.
Example 1: This example describes the basic example of $document service which prints a message on clicking a button each time.
HTML `