简体   繁体   English

我正在使用angular 2 angular-cli并尝试使用ng2-datetime,但出现错误“ TypeError:无法读取未定义的属性'jQuery'”

[英]I am using angular 2 angular-cli and try to use ng2-datetime,but it give error “TypeError: Cannot read property 'jQuery' of undefined”

I installed the angular2 cli using command "npm install -g angular-cli" and I want to use ng2-datetime in my project.But it is showing error "TypeError: Cannot read property 'jQuery' of undefined".How can I use ng2-datetime in angular2 cli. 我使用命令“ npm install -g angular-cli”安装了angular2 cli,我想在项目中使用ng2-datetime。但是它显示错误“ TypeError:无法读取未定义的'jQuery'属性”。如何使用在angular2 cli中的ng2-datetime。 Here is link for ng2-datetime enter link description here 这是ng2-datetime的链接,在此处输入链接描述

I want to include above ng2-datetime. 我想在ng2-datetime之前添加。

I got the following error. 我收到以下错误。 在此处输入图片说明

Here is my app.module 这是我的app.module

import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { Ng2PlayRoutingModule } from './app.routing'; import { AppComponent } from './app.component'; import { GridviewComponent } from './dashboard/gridview/gridview.component'; import { DetailsComponent } from './dashboard/details/details.component'; import { Logincomponent } from './login/login.component'; import { DashboardComponent } from './dashboard/dashboard.component'; import { DrilldownComponent } from './dashboard/drilldown/drilldown.component'; import { DropdownModule } from 'ng2-bootstrap'; import { WorkbenchComponent } from './workbench/workbench.component'; import { TasksComponent } from './workbench/tasks/tasks.component'; import { TaskdetailsComponent } from './workbench/taskdetails/taskdetails.component'; import { TopnavComponent } from './shared/topnav/topnav.component'; import { FieldfilterPipe } from './shared/pipes/fieldfilter.pipe'; import { LimitFirstNPipe } from './dashboard/details/limit-first-n.pipe'; import { DatepickerDirective } from './shared/directives/datepicker.directive'; import { CalendarComponent } from './workbench/calendar/calendar.component'; import { DateFilterPipe } from './workbench/calendar/date-filter.pipe'; import { StopscrollDirective } from './shared/directives/stopscroll.directive'; import { CapitalizePipe } from './workbench/tasks/capitalize.pipe'; import { ConfirmDeleteDirective } from './shared/directives/confirm-delete.directive'; import { NumberPipe } from './shared/pipes/number.pipe'; import { FilterPipe } from './shared/pipes/filter.pipe'; import { PriorityPipe } from './shared/pipes/priority.pipe'; import { TopnextnavComponent } from './shared/topnextnav/topnextnav.component'; import { ActiveTabDirective } from './shared/topnextnav/active-tab.directive'; import { AtozPipe } from './shared/pipes/atoz.pipe'; import { ExcludePipe } from './shared/pipes/exclude.pipe'; import { AddtaskComponent } from './workbench/addtask/addtask.component'; import { MomentFormatPipe } from './shared/pipes/moment-format.pipe'; import { JqteEditorDirective } from './shared/directives/jqte-editor.directive'; import { MultiselectComponent } from './shared/md2-comp/multiselect/multiselect.component'; import { TimepickerComponent } from './shared/md2-comp/timepicker/timepicker.component'; import { JquerydatepickerDirective } from './shared/directives/jquerydatepicker.directive'; import { DatefilterPipe } from './shared/pipes/datefilter.pipe'; import { Injectable } from '@angular/core'; import { EventService } from './shared/service/event.service'; import { DrilldownService } from './dashboard/drilldown/drilldown.service'; import { ActiveTab } from './shared/directives/activetab.directive'; import { NKDatetime } from 'ng2-datetime/ng2-datetime';

//import { NKDatetimeModule } from 'ng2-datetime/ng2-datetime';


@NgModule({   declarations: [
    AppComponent,
    GridviewComponent,
    DetailsComponent,
    Logincomponent,
    DashboardComponent,
    DrilldownComponent,
    WorkbenchComponent,
    TasksComponent,
    TaskdetailsComponent,
    TopnavComponent,
    FieldfilterPipe,
    LimitFirstNPipe,
    DatepickerDirective,
    CalendarComponent,
    DateFilterPipe,
    StopscrollDirective,
    CapitalizePipe,
    ConfirmDeleteDirective,
    DateFilterPipe,
    NumberPipe,
    FilterPipe,
    PriorityPipe,
    TopnextnavComponent,
    ActiveTabDirective,
    AtozPipe,
    ExcludePipe,
    AddtaskComponent,
    MomentFormatPipe,
    JqteEditorDirective,
    MultiselectComponent,
    TimepickerComponent,
    JquerydatepickerDirective,
    JquerydatepickerDirective,
    ActiveTab,
    NKDatetime   ],   imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    Ng2PlayRoutingModule,
    DropdownModule   ],   // exports: [NKDatetime],   providers: [EventService,DrilldownService],   bootstrap: [AppComponent] }) export class AppModule { }

drilldown.component.html drilldown.component.html

 <main class="container">
        <section>
            <div class="panel-body">
                <datetime [timepicker]="false" [(ngModel)]="date"></datetime>
            </div>
        </section>

    </main>

Try the below steps: 请尝试以下步骤:

  • install "ng2-datetime": "1.2.1" 安装"ng2-datetime": "1.2.1"
  • install "@types/jquery": "^2.0.33" 安装"@types/jquery": "^2.0.33"
  • specify "types": ["jquery"] within tsconfig.json tsconfig.json中指定"types": ["jquery"]

This worked for me. 这对我有用。

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

相关问题 Angular 4 + ng2-datetime jQuery问题 - Angular 4 + ng2-datetime jQuery issue 我不断收到此错误“ angular.js:TypeError:无法读取未定义的属性&#39;pages&#39;” - I keep getting this error “angular.js:TypeError: Cannot read property 'pages' of undefined” 在 Angular-CLI 项目中使用 jQuery - Using jQuery with Angular-CLI Project angular-cli选择了jquery - angular-cli chosen jquery 使用jQuery的自定义JavaScript代码在Angular 5(angular-cli)中不起作用 - Custom javascript code using jQuery is not working Angular 5 (angular-cli) Angular 1.3:TypeError:无法在 ng-submit 上读取空错误的属性“0” - Angular 1.3 : TypeError: Cannot read property '0' of null error on ng-submit TypeError:无法读取未定义的属性“数据集”-角度图 - TypeError: Cannot read property 'datasets' of undefined - Angular Chart Uncaught TypeError:无法读取未定义的属性“行”在Angular JS中不起作用 - Uncaught TypeError: Cannot read property 'row' of undefined is not working in angular js angular.js:12520 TypeError:无法读取未定义的属性&#39;post&#39; - angular.js:12520 TypeError: Cannot read property 'post' of undefined 为什么我收到此错误?Uncaught TypeError:无法读取未定义的属性“ length” - why I am getting this error Uncaught TypeError: Cannot read property 'length' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM