angular.module('myApp').controller('myCtrl', function($scope, $document) { var myElement = $document[0].getElementById('myId'); });
angular.module('myApp').controller('myCtrl', function($scope, $window) { $window.alert('Hello World!'); });
// 错误示例 var myElement = document.getElementById('myId');
// 正确示例 angular.module('myApp').controller('myCtrl', function($scope, $document) { var myElement = $document[0].getElementById('myId'); });
angular.module('myApp').controller('myCtrl', function($scope, $timeout) { $timeout(function() { // 更改DOM }); });
angular.module('myApp').controller('myCtrl', function($scope) { $scope.myValue = 'Initial Value';
$scope.$watch(function() { return document.getElementById('myId').innerHTML; }, function(newValue, oldValue) { $scope.myValue = newValue; }); });