top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is difference between $document and window.document in AngularJS?

0 votes
382 views
What is difference between $document and window.document in AngularJS?
posted Nov 18, 2017 by Jayshree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

$document is an Angular service which reference to the browser's window.document object.

<script>
 var app = angular.module('documentExample', []);
 app.controller('ExampleController', ['$scope', '$document', function ($scope,
$document) {
 $scope.title = $document[0].title;
 $scope.windowTitle = angular.element(window.document)[0].title;
 }]);
</script>
<div ng-app="documentExample" ng-controller="ExampleController">
 <p>$document title: <b ng-bind="title"></b></p>
 <p>window.document title: <b ng-bind="windowTitle"></b></p>
</div>
answer Nov 18, 2017 by Shivaranjini
...