【问题标题】:ng2-datepicker isn't workingng2-datepicker 不工作
【发布时间】:2017-02-16 01:03:09
【问题描述】:

我正在尝试在我的 Angular 2 应用程序中使用 ng2-datepicker。我按照上面页面中的说明进行操作,但日期选择器没有出现。控制台记录以下错误。

url_resolver.js:248 Uncaught TypeError: uri.match is not a function

我的app.module.ts

import { DatePicker } from 'ng2-datepicker/ng2-datepicker';

@NgModule({
    declarations: [
        AppComponent,
        DatePicker
    ],

app.component.html

<datepicker [(ngModel)]="date" [expanded]="true"></datepicker>

Angular 2.0.0 版

package.json

"dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "@material2-extra/calendar": "0.0.14-1",
    "core-js": "^2.4.1",
    "moment": "^2.15.1",
    "ng2-datepicker": "^1.1.0",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },

有什么建议吗?

谢谢

【问题讨论】:

  • 你用的是哪个 angular 2 版本,在 RC7 中已经解决了
  • 我使用的是 Angular 2 稳定版

标签: angular datepicker ng2-datepicker


【解决方案1】:

从 Angular 2.0.0 开始,这是一个持续存在的问题,如果您使用 webpack 并且包(在您的情况下为 ng2-datepicker)有一个使用 module.id 的组件,您将收到此错误。根据this issue,它已在 2.0.1 中修复,但我没有机会确认。希望迁移到该版本会为您解决问题。

如果不是,我的两个包都遇到了问题,不得不移动 html 和 css 内联以支持 webpack 用户。您可以联系软件包的发布者,看看他们是否会使用该解决方法。

【讨论】:

    【解决方案2】:

    https://github.com/angular/material2/issues/974

    什么是模块构建器,有什么用?

    不要在组件中使用 module.id。

    【讨论】:

    • 我没有在组件中使用module.id。
    猜你喜欢
    • 2017-05-01
    • 2017-03-23
    • 1970-01-01
    • 2016-09-02
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    相关资源
    最近更新 更多