[英]How do I use mobile-detect.js in an Aurelia typescript app?
I am not sure how to use mobile-detect.js in a Aurelia Typescript app. 我不确定如何在Aurelia Typescript应用程序中使用mobile-detect.js。 I figured mobile-detect should be instantiated as soon as possible so I tried to put it in main.ts like so:
我认为应该尽快实例化mobile-detect,因此我尝试将其放置在main.ts中,如下所示:
/// <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. 因此,模块加载器对npm模块一无所知。 Try using JSPM or just doing something like import { MobileDetect } from 'node_modules/path/to/mobiledetect'
尝试使用JSPM或仅从'node_modules / path / to / mobiledetect'中执行import {MobileDetect}
Weird. 奇怪的。 It seems when I comment out the import like the following it works.
似乎当我像下面这样注释掉导入时,它起作用了。
/// <reference path="../typings/mobile-detect/mobile-detect.d.ts" />
//import 'MobileDetect';
//import { MobileDetect } from '../../lib/mobile-detect/mobile-detect';
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.