[英]How do I use mobile-detect.js in an Aurelia typescript app?
我不確定如何在Aurelia Typescript應用程序中使用mobile-detect.js。 我認為應該盡快實例化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
}
}
顯然,這不是正確的方法。 有人可以指出我正確的方向嗎?
謝謝 :-)
因此,模塊加載器對npm模塊一無所知。 嘗試使用JSPM或僅從'node_modules / path / to / mobiledetect'中執行import {MobileDetect}
奇怪的。 似乎當我像下面這樣注釋掉導入時,它起作用了。
/// <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.