My goal was to create a basic app that could detect the size of the browser and display it. But, I encountered an error message saying "Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!"
app.controller('AppCtrl',function($window,$scope){
$scope.windowHeight;
$scope.windowWidth;
$scope.getWindowSize = function(){
return {
h:$window.innerHeight,
w:$window.innerWidth
};
};
$scope.$watch($scope.getWindowSize,function (newValue,oldValue){
$scope.windowHeight = newValue.h;
$scope.windowWidth = newValue.w;
});
});
Here is my HTML Template:
<!DOCTYPE html>
<html ng-app="size-util">
<head>
<title></title>
<script src="angular.js"></script> <script src="colorBorder.js"></script>
</head>
<body ng-controller="AppCtrl">
<div color-border='blue'>Welcome!</div>
{{windowHeight}} {{windowWidth}}
</body>
</html>
The structure above showcases my code but it seems like there's an issue. Was my approach with the $watch method incorrect? I can't seem to figure out where the problem lies. Any suggestions?