简体   繁体   English

如何在Aurelia打字稿应用程序中使用mobile-detect.js?

[英]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.

相关问题 如何将Aurelia入门教程与TypeScript一起使用? - How to use Aurelia Getting Started tutorial with TypeScript? 在Aurelia中使用带有Typescript的Jquery - Use Jquery in Aurelia with Typescript 如何使用Aurelia / Typescript导入和使用PhotoSwipe? - How to import and use PhotoSwipe with Aurelia / Typescript? 我想创建仅允许数字的文本框。 如何使用aurelia中的Typescript做到这一点? - I want to Create textbox which allows only numbers. How can I do that with Typescript in aurelia? 我想在文本框中自动添加破折号 (-)。 如何在 aurelia typescript 应用程序中执行此操作? - I want to automatically add dashes (-) in a textbox. How can I do this in an aurelia typescript application? Javascript / Typescript:如何在Android应用中检测有效的联系人和电话号码 - Javascript/Typescript: How do I detect valid contacts and phone numbers in Android app 如何在带有 TypeScript 的 React 应用程序中使用消费者? - How do I use a Consumer in a React app with TypeScript? Aurelia / Typescript-如何通过选择标签将对象绑定到变​​量 - Aurelia/Typescript - How do I bind an object to a variable thru select tag 如何在没有打字稿定义文件的情况下使用Aurelia第三方插件? - How to use Aurelia third party plugin with without typescript definition file? 如何在打字稿aurelia cli项目中使用gulp调用au build? - how to use gulp to call au build in a typescript aurelia cli project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM