mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Move use of `$window` from template to controller, because accessing `$window` in expressions is now disallowed and doesn't work. Closes #5110
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* @ngdoc object
|
|
* @name ng.$window
|
|
*
|
|
* @description
|
|
* A reference to the browser's `window` object. While `window`
|
|
* is globally available in JavaScript, it causes testability problems, because
|
|
* it is a global variable. In angular we always refer to it through the
|
|
* `$window` service, so it may be overridden, removed or mocked for testing.
|
|
*
|
|
* 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.
|
|
*
|
|
* @example
|
|
<doc:example>
|
|
<doc:source>
|
|
<script>
|
|
function Ctrl($scope, $window) {
|
|
$scope.greeting = 'Hello, World!';
|
|
$scope.doGreeting = function(greeting) {
|
|
$window.alert(greeting);
|
|
};
|
|
}
|
|
</script>
|
|
<div ng-controller="Ctrl">
|
|
<input type="text" ng-model="greeting" />
|
|
<button ng-click="doGreeting(greeting)">ALERT</button>
|
|
</div>
|
|
</doc:source>
|
|
<doc:scenario>
|
|
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();
|
|
});
|
|
</doc:scenario>
|
|
</doc:example>
|
|
*/
|
|
function $WindowProvider(){
|
|
this.$get = valueFn(window);
|
|
}
|