Skip to content

Instantly share code, notes, and snippets.

@znechai
Last active April 1, 2017 19:50
Show Gist options
  • Save znechai/d288a7f0921e6770c00fed3d4d4f5242 to your computer and use it in GitHub Desktop.
Save znechai/d288a7f0921e6770c00fed3d4d4f5242 to your computer and use it in GitHub Desktop.
Angular - Device Detector Factory
function useragent($q, $window) {
return {
// Get user agent
getUserAgent: function () {
var deffered = $q.defer();
if ($window.navigator && $window.navigator.userAgent){
var ua = $window.navigator.userAgent;
deffered.resolve(ua);
}
return deffered.promise;
},
// Get if user connected via mobile or desktop using params from above function
getIcon: function (ua) {
var deffered = $q.defer();
var icon = ua.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i) ? 'mobile' : 'desktop';
deffered.resolve(icon);
return deffered.promise;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment