UNPKG

knowhow-server

Version:

A personal workflow engine that can manage and use any network connected host

54 lines (52 loc) 2.87 kB
<a href="http://github.com/angular/angular.js/tree/v1.2.9/src/ng/window.js#L3" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ng/window.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">$window</code> <div><span class="hint">service in module <code ng:non-bindable="">ng</code> </span> </div> </h1> <div><h2 id="description">Description</h2> <div class="description"><div class="ng-window-page"><p>A reference to the browser&#39;s <code>window</code> object. While <code>window</code> is globally available in JavaScript, it causes testability problems, because it is a global variable. In angular we always refer to it through the <code>$window</code> service, so it may be overridden, removed or mocked for testing.</p> <p>Expressions, like the one defined for the <code>ngClick</code> directive in the example below, are evaluated with respect to the current scope. Therefore, there is no risk of inadvertently coding in a dependency on a global value in such an expression.</p> </div></div> <h2 id="example">Example</h2> <div class="example"><div class="ng-window-page"><h4 id="example_source">Source</h4> <div source-edit="" source-edit-deps="angular.js script.js" source-edit-html="index.html-162" source-edit-css="" source-edit-js="script.js-161" source-edit-json="" source-edit-unit="" source-edit-scenario="scenario.js-163" source-edit-protractor=""></div> <div class="tabbable"><div class="tab-pane" title="index.html"> <pre class="prettyprint linenums" ng-set-text="index.html-162" ng-html-wrap=" angular.js script.js"></pre> <script type="text/ng-template" id="index.html-162"> <div ng-controller="Ctrl"> <input type="text" ng-model="greeting" /> <button ng-click="doGreeting(greeting)">ALERT</button> </div> </script> </div> <div class="tab-pane" title="script.js"> <pre class="prettyprint linenums" ng-set-text="script.js-161"></pre> <script type="text/ng-template" id="script.js-161"> function Ctrl($scope, $window) { $scope.greeting = 'Hello, World!'; $scope.doGreeting = function(greeting) { $window.alert(greeting); }; } </script> </div> <div class="tab-pane" title="ngScenario e2e test"> <pre class="prettyprint linenums" ng-set-text="scenario.js-163"></pre> <script type="text/ng-template" id="scenario.js-163"> it('should display the greeting in the input box', function() { input('greeting').enter('Hello, E2E Tests'); // If we click the button it will block the test runner // element(':button').click(); }); </script> </div> </div><h4 id="example_demo">Demo</h4> <div class="well doc-example-live animate-container" ng-embed-app="" ng-set-html="index.html-162" ng-eval-javascript="script.js-161"></div> </div></div> </div>