ng-datetime datepicker不是函数

时间:2016-12-08 15:32:42

标签: angular

我一直在研究ng-datetime作为一个选项,用于我正在工作的应用程序的日期选择器。我按照说明:https://www.npmjs.com/package/ng2-datetime写了这封信。

我在安装ng-datetime之前安装了两个依赖项(bootstrap datepicker和bootstrap timepicker),并添加了对app.module文件的引用。

然而,当我在我的html页面中使用它时,我可以看到控件本身,但它是静态的,我想出了错误: $(...)。datepicker不是函数

我发现其他3个问题可以解决这个错误,但在这些帖子中没有看到任何适用于我的解决方案,因此是重复的问题。

2 个答案:

答案 0 :(得分:1)

我们已将以下条目添加到angular.cli.json`并且它可以正常工作。(angular 4.2)

`"styles": [
    "styles.css",
    "../node_modules/font-awesome/css/font-awesome.css",
    "../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css"
],
"scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js",
    "../node_modules/bootstrap-timepicker/js/bootstrap-timepicker.js"
]`

答案 1 :(得分:0)

我遇到了与webpack相同的问题, 我有以下关于webpack的条目

config.entry = {
     webapp:['./client/main.js'], //application generated code will be here 
     polyfills:['./client/polyfills.browser.js'], //pollyfills will be here
     vendor:['./client/vendor.browser.js'] //external vendor files will be here.
};

我的jQuery已添加到vendor.browser.ts文件中。并遵循代码

import { NKDatetime } from 'ng2-datetime/ng2-datetime';  
@Component({   
    ...    
    directives: [NKDatetime],  
})

在app.module.ts文件中。所以它无法在那里获取jQuery。

所以我做了以下更改。

设置以下代码

import { NKDatetime } from 'ng2-datetime/ng2-datetime';
export {NKDatetimeModule} //export the ng2 module from the vendor.ts file.

在vendor.ts文件中。

//import the exported ng2-datetime module here.
import { NKDatetimeModule } from '../../vendor.browser'; 
@Component({
    ...
    directives: [NKDatetime],
})

在我的app.module.ts文件中。

它有效......