带有或不带有jQuery的Angular

带有或不带有jQuery的Angular

本文介绍了带有或不带有jQuery的Angular 2+中的Bootstrap 3 Datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Angular 2+的新手.我正在尝试将Bootstrap 3 Datepicker集成到AngularJS2.我使用了[解决方案]:如何在角度2 .但是出现了类似的错误

I am new to Angular 2+. I am trying to integrate Bootstrap 3 Datepicker inAngularJS2. I used the [solution]: How to use Bootstrap 3 Datepicker in angular 2. But got error like

Cannot find name '$'

有没有jquery可以实现任务吗?

Is there any way to implement the task with or without jquery?

下面提供了我的代码.

index.html

index.html

 <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
 <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
 <script
 src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"
 integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30="
 crossorigin="anonymous"></script>
 <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">   </script>

new-job.component.html

new-job.component.html

<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
   <input type='text' class="form-control" id='proposed_start_at' formControlName="proposed_start_at" #proposed_start_at/>
   <label class="mdl-textfield__label" for="proposed_start_at">Start Time</label>
</div>

new-job.component.ts

new-job.component.ts

@ViewChild("proposed_start_at")
public startDateElementRef: ElementRef;

ngAfterViewInit() {
    $(this.startDateElementRef.nativeElement).datetimepicker({format: 'LT'});
}

我想实现在[link]中提供的datetimepicker: https://eonasdan.github .io/bootstrap-datetimepicker/

I want to implement datetimepicker which is given in [link]: https://eonasdan.github.io/bootstrap-datetimepicker/

推荐答案

您需要添加:declare var $:any;

declare var $: any;

@Component({
    ...
})

请确保您的书房中有所有必需的书房:

Be sure to have all required librairies in your librairies:

npm install jquery bootstrap moment eonasdan-bootstrap-datetimepicker--save

然后在angular-cli.json中

then in angular-cli.json

"styles": ["../node_modules/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css"],
"scripts": [
      "../node_modules/jquery/dist/jquery.js",
      "../node_modules/bootstrap/dist/js/bootstrap.js",
      "../node_modules/moment/moment.js",
      "../node_modules/eonasdan-bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js",
      ...

并且您不需要在index.html的scripts标签中添加这些

And you dont need to add these in scripts tags in index.html

这篇关于带有或不带有jQuery的Angular 2+中的Bootstrap 3 Datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:32