AngularJs-$document-1

 

$document is a service and work as a wrapper to access title, cookie and body of document. To access its property either we need to use prop or index[] and access them. In our example, we will display the title of the document. See the code snippet: $scope.title = $document[0].title;

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="controllerName"> <p>$document title : <b ng-bind="title"></b></p> </div> </body> </html> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', '$document', function ($scope, $document) { $scope.title = $document[0].title; }]); </script>
Output