0
我有一條指令用於檢測移動瀏覽器,而我目前將它添加到指令中。但是,我通常需要在應用程序的多個位置檢查移動瀏覽器,並且想知道在我的角度應用程序的運行模塊中執行檢查是否更有意義,然後使用值存儲它,是可用的整個應用程序?檢查角度運行塊中的移動瀏覽器而不是指令
angular.module('app')
.directive('windowResized', function($window) {
return {
restrict: 'A',
link: function(scope, elem, attr) {
var ua = $window.navigator.userAgent,
iPhone = ua.indexOf('iPhone') !== -1 || ua.indexOf('iPod') !== -1,
iPad = ua.indexOf('iPad') !== -1,
iOs = iPhone || iPad,
android = ua.indexOf('Android') !== -1;
//do something
}
}
})
謝謝,這是有道理的,我相應地重構了我的代碼! –