$scope.getBrickHeight = function(){ if( $scope.brickHeight === undefined ){ $scope.brickHeight = ( ( jQuery(document).width() / jQuery(document).height() ) * 40 ) + '%'; } return $scope.brickHeight; }