Javascript AngularJS:仅横向模式,但“方向更改”在AngularJS中不起作用
我试图让我的应用程序只在横向模式下工作,我必须显示一个文本,比如如果用户处于纵向模式,请使用横向模式,并且全部使用AngularJS。 我在jQuery中尝试了它,它工作得非常好,但是我们没有使用jQuery,所以我也必须使用AngularJS 这是我的简单控制器:Javascript AngularJS:仅横向模式,但“方向更改”在AngularJS中不起作用,javascript,angularjs,orientation,landscape,portrait,Javascript,Angularjs,Orientation,Landscape,Portrait,我试图让我的应用程序只在横向模式下工作,我必须显示一个文本,比如如果用户处于纵向模式,请使用横向模式,并且全部使用AngularJS。 我在jQuery中尝试了它,它工作得非常好,但是我们没有使用jQuery,所以我也必须使用AngularJS 这是我的简单控制器: app.controller('rootCtrl', ['$scope', '$http', function ($scope, $http) { window.addEventListener("orientationch
app.controller('rootCtrl', ['$scope', '$http', function ($scope, $http) {
window.addEventListener("orientationchange", function() {
if(window.orientation == 0) {
// alert(window.orientation) : I get this value when rotate my device
$scope.islandscape = false;
}else {
// alert(window.orientation) : I get this value when rotate my device
$scope.islandscape = true;
}
}, false);
}])
以下是我的看法:
<div id="p" ng-show="islandscape == false">
<h1 style="width: 90%; margin: 2em auto; font-size: 4em;">Please Use Landscape Mode</h1>
</div>
<div id="l" ng-show="islandscape == true">
<div ng-include="'templates/header.htm'"></div>
<div id="dataContent" ng-view></div>
<div ng-include="'templates/footer.htm'"></div>
</div>
我是AngularJS的新手,不确定我错过了什么,或者我的逻辑是否正确。如何使其正常工作?不要使用addEventListener,而是对$scope.apply-angularwindow.onorientationchange函数{$scope.applyfunction{/*CODE*/};}使用角度事件处理@兰:我试过了,但没用。
$(document).ready(function() {
readDeviceOrientation();
});
function readDeviceOrientation() {
if (Math.abs(window.orientation) === 90) {
$("#p").hide();
$("#l").show();
} else {
$("#l").hide();
$("#p").show();
}
}
window.onorientationchange = readDeviceOrientation;