是否有方法在AngularJS指令中调用orientationchange事件?
我目前正在使用角砌石,我正在尝试更新/刷新当移动设备的方向改变时,砖石结构。
我已经找到了这个,但我想知道如何使用Angular 中的$window服务来做到这一点
window.addEventListener("orientationchange", function() {
// Announce the new orientation number
console.log(window.orientation);
}, false);
angular.element($window).bind('orientationchange', function () {
});
希望这能有所帮助。将指令作为attr附加到正文。使用IPhone 5进行测试。
'use strict';
angular.module('appModuleNameHere')
.directive('DirPrefixNameOrientationChange', ['$rootScope',function ($state) {
return {
restrict: 'A',
replace: true,
link: function postLink($scope, element, attrs) {
element.bind('orientationchange', function () {
$state.go($state.current, {}, {reload: true});
});
}
};
}]);
我是这样实现的:
$window.addEventListener('orientationchange', function() {
your code here
}, false);
你觉得怎么样?
欢迎发表意见。