2011-07-17 08:05:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2011-02-15 06:12:45 +00:00
|
|
|
/**
|
2011-11-10 06:23:36 +00:00
|
|
|
* @ngdoc object
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.$window
|
2011-02-15 06:12:45 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
2011-02-14 18:17:04 +00:00
|
|
|
* A reference to the browser's `window` object. While `window`
|
2011-02-15 06:12:45 +00:00
|
|
|
* is globally available in JavaScript, it causes testability problems, because
|
|
|
|
|
* it is a global variable. In angular we always refer to it through the
|
2013-03-21 19:09:47 +00:00
|
|
|
* `$window` service, so it may be overridden, removed or mocked for testing.
|
2011-02-15 06:12:45 +00:00
|
|
|
*
|
2013-07-21 17:25:23 +00:00
|
|
|
* Expressions, like the one defined for the `ngClick` 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.
|
2011-02-15 06:12:45 +00:00
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
2013-05-09 11:42:19 +00:00
|
|
|
<script>
|
|
|
|
|
function Ctrl($scope, $window) {
|
|
|
|
|
$scope.$window = $window;
|
|
|
|
|
$scope.greeting = 'Hello, World!';
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<div ng-controller="Ctrl">
|
|
|
|
|
<input type="text" ng-model="greeting" />
|
|
|
|
|
<button ng-click="$window.alert(greeting)">ALERT</button>
|
|
|
|
|
</div>
|
2011-02-15 06:12:45 +00:00
|
|
|
</doc:source>
|
|
|
|
|
<doc:scenario>
|
2013-05-09 11:42:19 +00:00
|
|
|
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();
|
|
|
|
|
});
|
2011-02-15 06:12:45 +00:00
|
|
|
</doc:scenario>
|
|
|
|
|
</doc:example>
|
|
|
|
|
*/
|
2011-11-02 23:32:46 +00:00
|
|
|
function $WindowProvider(){
|
|
|
|
|
this.$get = valueFn(window);
|
|
|
|
|
}
|