This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Values

Look up browser objects that AngularTS exposes through dependency injection.

Injected values provide testable access to browser globals such as document and window. Learn dependency injection before using this reference.

1 - $document

Injectable window.document object

Description

An injectable wrapper for window.document object . Useful for mocking a browser dependency in non-browser environment tests:

Example:

// value injectables are overriden
angular.createModule('demo', []).value('$document', {});

When combined with ng-inject directive, the wrapper also makes document object directly accessible in the template scope.

Demo

<section ng-app>
  <div ng-inject="$document">
    `document.location.host` == <b>{{ $document.location.host }}</b>
  </div>
</section>
`document.location.host` == {{ $document.location.host }}

2 - $window

Injectable window object

Description

An injectable wrapper for window object . Useful for mocking a browser dependency in non-browser environment tests:

Example:

// value injectables are overriden
angular.createModule('demo', []).value('$window', {});

When combined with ng-inject directive, the wrapper also makes window object directly accessible in the template scope.

Demo

<section ng-app>
  <div ng-inject="$window"></div>
  <button class="btn btn-dark" ng-click="$window.alert('click')">Alert</button>
</section>