©
このドキュメントでは、php中国語ネットマニュアルリリース
A reference to the browser'swindow
object. Whilewindow
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 thengClick
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.
angular.module('windowExample',[]).controller('ExampleController',['$scope','$window',Function($scope,$window){$scope.greeting='Hello, World!';$scope.doGreeting=Function(greeting){$window.alert(greeting);};}]);ng-controller="ExampleController">Type="text"ng-model="greeting"/>
it('should display the greeting in the input box',Function(){element(by.model('greeting')).sendKeys('Hello, E2E Tests');// If we click the button it will block the test runner// element(':button').click();});