Ответ 1
Основная проблема: вам нужно добавить единицы "px" в число window.innerHeight
. И второе, имя переменной iframeHeight
not iframeHeight
. Фиксированное выражение будет выглядеть так:
ng-style="{height: iframeHeight + 'px'}"
Я использую iframe для отображения содержимого с использованием угловых элементов с ионным каркасом. Здесь мне нужно указать высоту окна как высоту iframe, поэтому я использовал
$scope.iframeHeight = window.innerHeight;
Но я получаю только 1/4-й экран.
Вот что я пробовал до сих пор.
index.html
<!DOCTYPE html>
<html ng-app="ionicApp">
<head>
<!-- ionic/angularjs CSS -->
<link href="css/ionic.css" rel="stylesheet">
<link href="css/ionic-custom.css" rel="stylesheet">
<!-- ionic/angularjs js bundle -->
<script type="text/javascript" src="js/ionic.bundle.js"></script>
<script>
angular.module('ionicApp', ['ionic'])
.controller('MainCtrl', function($scope) {
$scope.iframeHeight = window.innerHeight;
});
</script>
</head>
<body ng-controller="MainCtrl">
<iframe src="http://stackoverflow.com" ng-style="{height:iFrameHeight}" id="iframeid" width="100%" ></iframe>
</body>
</html>
Я что-то пропустил?
Основная проблема: вам нужно добавить единицы "px" в число window.innerHeight
. И второе, имя переменной iframeHeight
not iframeHeight
. Фиксированное выражение будет выглядеть так:
ng-style="{height: iframeHeight + 'px'}"
Объект window, хотя доступен по всему миру, имеет проблемы с тестируемостью в качестве ссылки в окне angular docs https://docs.angularjs.org/api/ng/service/ $. Он выглядит как его не проблема на вашем коде, но для хорошей практики вы можете ввести услугу $window, а затем ссылаться на нее и, конечно, на проблему "px" внизу.
angular.module('ionicApp', ['ionic'])
.controller('MainCtrl', function($scope, $window) {
$scope.iframeHeight = $window.innerHeight;
});
Позже, как сказано ранее,
ng-style="{height: iframeHeight + 'px'}"
Так как AngularJS содержит небольшую часть jQuery, вы можете использовать:
// Returns height of browser viewport
$scope.iframeHeight = $(window).height();
или
// Returns height of HTML document
$scope.iframeHeight = $(document).height();
Высота окна Calculte с помощью angular
$scope.screenHeight = '';
$scope.calculateoriginalWidth = function() {
var width = $window.innerWidth;
$rootScope.originalWidth = width;
}
$scope.calculateScreenHeight = function() {
var height = $window.innerHeight;
var width = $window.innerWidth;
var subheight = 0;
var headerheight = document.getElementById('headerTitle1');
var headerheight2 = document.getElementById('headerTitle2');
if (headerheight) {
subheight += headerheight.offsetHeight;
}
if (headerheight2) {
subheight += headerheight2.offsetHeight;
}
$scope.screenHeight = height - subheight - 20;
$rootScope.screenHeight = $scope.screenHeight;
$scope.screenWidth = width;
$rootScope.screenWidth = $scope.screenWidth;
}
var reg = $scope.$on('screenResize', function($evt, args) {
$scope.calculateScreenHeight();
$scope.$apply();
})
window.onresize = function(event) {
$scope.$apply(function() {
$scope.calculateScreenHeight();
})
};
$scope.calculateScreenHeight();
$scope.calculateoriginalWidth();
Для использования этого кода необходимо добавить необходимые зависимости в angular. Надеюсь, это поможет вам рассчитать высоту окна.