7

How can I use mobile-detect.js in an Aurelia application?

 3 years ago
source link: https://www.codesd.com/item/how-can-i-use-mobile-detect-js-in-an-aurelia-application.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How can I use mobile-detect.js in an Aurelia application?

advertisements

I am not sure how to use mobile-detect.js in a Aurelia Typescript app. I figured mobile-detect should be instantiated as soon as possible so I tried to put it in main.ts like so:

/// <reference path="../typings/mobile-detect/mobile-detect.d.ts" />

import 'MobileDetect';
import {Aurelia} from 'aurelia-framework';

export function configure(aurelia: Aurelia) {
   aurelia.use
    .standardConfiguration()
    .developmentLogging();

aurelia.use.plugin('aurelia-animator-css');
aurelia.start().then(a => a.setRoot());

var md = new MobileDetect(window.navigator.userAgent);

if (md.mobile()) {

   //Do Something

}
else {

   //Do Something Else
 }
}

Obviously this is not the right way to do it. Can someone point me in the right direction?

Thanks :-)


So, the module loader doesn't know anything about npm modules. Try using JSPM or just doing something like import { MobileDetect } from 'node_modules/path/to/mobiledetect'


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK