简体   繁体   English

如何将'bootstrap-datetimepicker'导入Aurelia项目

[英]How to import 'bootstrap-datetimepicker' into Aurelia project

I'm trying to add 'Eonasdan/bootstrap-datetimepicker' into an Aurelia with typescript project and call this.birthDateDatePicker.datetimepicker(); 我试图将'Eonasdan / bootstrap-datetimepicker'添加到带有打字稿项目的Aurelia中,并调用this.birthDateDatePicker.datetimepicker(); in the "attached" method from the Aurelia life-cycle. 在Aurelia生命周期的“附加”方法中。

I added: 我补充说:

import $ from 'jquery'; 
import {datepicker} from 'Eonasdan/bootstrap-datetimepicker';

and there was no error, but when I try to inject like this @inject(HttpClient, json, datepicker) I get the following error: 并且没有错误,但是当我尝试像这样@inject(HttpClient, json, datepicker)注入时@inject(HttpClient, json, datepicker)出现以下错误:

GET http://127.0.0.1:8080/jquery.js 404 (Not Found) GET http://127.0.0.1:8080/jquery.js 404(未找到)

I'm not sure the two libraries are loaded because I cannot find them in the sources on the browser debugger. 我不确定这两个库是否已加载,因为我无法在浏览器调试器的源代码中找到它们。

What am I doing wrong? 我究竟做错了什么?

EDIT: 编辑:

image with more info 带有更多信息的图像

The error on that line is 那条线上的错误是

"Unhandled promise rejection TypeError: this.birthDateDatePicker.datetimepicker is not a function" “未处理的承诺拒绝TypeError:this.birthDateDatePicker.datetimepicker不是函数”

SOLUTION: 解:

I've added the following imports: 我添加了以下导入:

import $ from 'jquery';
import 'Eonasdan/bootstrap-datetimepicker';

and manually added in the config.js the fallowing map: 并在config.js中手动添加休憩地图:

"jquery":"github:components/jquery@2.2.0",

Comment/Question: I'm not sure if it's a good idea to manually add it there but I could not use it from bootstrap like in the skeleton application and I saw it was present in the global dependencies of the package.json file and found it under "jspm_packages/github/components". 评论/问题:我不确定在此处手动添加它是否是一个好主意,但是我无法像骨架应用程序那样从引导程序中使用它,我发现它存在于package.json文件的全局依赖项中并找到它在“ jspm_packages / github / components”下。

Is this a correct approach? 这是正确的方法吗?

Thanks 谢谢

aha, it wasn't clear to me what you were doing when we were chatting in the gitter. 啊哈,当我在混乱中聊天时,我不清楚你在做什么。 I think I see the issue now... 我想我现在看到了这个问题...

The bootstrap-datetimepicker is a jQuery plugin, loading the module installs the plugin's functionality in jquery. bootstrap-datetimepicker是一个jQuery插件,加载模块将在jQuery中安装该插件的功能。 It may not export anything. 它可能不会导出任何内容。 If it does export something, it should be the jquery object. 如果确实导出某些内容,则应为jquery对象。

Try one of these: 尝试以下方法之一:

import $ from 'Eonasdan/bootstrap-datetimepicker';
import $ from 'jquery';
import 'Eonasdan/bootstrap-datetimepicker';

In any of these cases, there's no need to involve dependency injection ( @inject etc). 在任何这些情况下,都不需要涉及依赖项注入( @inject等)。 Use the $ variable directly. 直接使用$变量。

if you use aurelia-skeleton as boilerplate 如果您使用aurelia骨架作为样板

import $ from 'bootstrap';

EDITED: Also use import 'Eonasdan/bootstrap-datetimepicker'; 编辑:也可以使用import 'Eonasdan/bootstrap-datetimepicker'; to add datetimepicker as jquery module to globals 将datetimepicker作为jquery模块添加到全局变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM