我正在尝试检查角度中方向更改的工作,但它不起作用。
var myApp = angular.module('myApp',['ngTouch','matchmedia-ng']);
function checkOrientation($scope){
if($scope.landscape){
$scope.isLandscape="landscape";
alert($scope.isLandscape);
}
else{
$scope.isLandscape="portrait";
alert($scope.isLandscape);
}
}
myApp.controller('MainController', ['$scope', '$window','matchmedia',
function($scope, $window, matchmedia) {
$scope.submit = function() {
alert("submitted!");
}
$scope.desktop = matchmedia.isDesktop();
$scope.tablet =matchmedia.isTablet();
$scope.phone = matchmedia.isPhone();
$scope.landscape = matchmedia.isLandscape();
if($scope.desktop){
alert("desktop");
}
else if($scope.tablet){
alert("tablet");
}
else if($scope.phone){
$scope.isDevice = 'phone';
}
checkOrientation($scope);
/*screen.bind('orientationchange', function () {
$route.reload();
});*/
angular.element($window).bind('orientationchange', function ($scope) {
checkOrientation($scope);
});
}]);
我也尝试过$ route.reload()的选项,但它也不起作用。它工作但不是我改变方向时。
答案 0 :(得分:0)
在checkOrientation中,您只需查看以下内容的值即可了解您所处的方向:
$window.screen.orientation.type