ngx-bootstrap 日期选择器不起作用

2024-03-28

我正在学习 Angular2 和 Bootstrap4。我的公司使用以下网站。http://valor-software.com/ngx-bootstrap/#/datepicker http://valor-software.com/ngx-bootstrap/#/datepicker日历显示了,但如果我单击某些内容,则什么也不会发生。 我不知道为什么该网站无法移动。有谁能帮帮我吗?

*应用程序.组件.html:

<style>
  .full button span {
    background-color: limegreen;
    border-radius: 32px;
    color: black;
  }
  .partially button span {
    background-color: orange;
    border-radius: 32px;
    color: black;
  }
</style>

<div>
  <div class="card">
    <pre class="card-block card-header">Selected date is: <em *ngIf="dt">{{ getDate() | date:'fullDate'}}</em></pre>
  </div>
  <h4>Inline</h4>
  <div style="display:inline-block; min-height:290px;">
    <datepicker [(ngModel)]="dt" [minDate]="minDate" [showWeeks]="true" [dateDisabled]="dateDisabled"></datepicker>
  </div>

  <hr />
  <button type="button" class="btn btn-sm btn-info" (click)="today()">Today</button>
  <button type="button" class="btn btn-sm btn-default btn-secondary" (click)="d20090824();">2009-08-24</button>
  <button type="button" class="btn btn-sm btn-danger" (click)="clear()">Clear</button>
  <button type="button" class="btn btn-sm btn-default btn-secondary" (click)="toggleMin()" tooltip="After today restriction">Min date</button>
  <button type="button" class="btn btn-sm btn-default btn-secondary" (click)="disableTomorrow()">Disable Tomorrow</button>
</div>

*应用程序模块.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { DatepickerModule } from 'ngx-bootstrap/datepicker';

import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { ModalModule } from 'ngx-bootstrap/modal';
import { PaginationModule } from 'ngx-bootstrap/pagination';
import { TypeaheadModule } from 'ngx-bootstrap/typeahead';
import { ButtonsModule } from 'ngx-bootstrap/buttons';
import { FormsModule } from '@angular/forms';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    DatepickerModule.forRoot(), ButtonsModule.forRoot(), TypeaheadModule.forRoot(), PaginationModule.forRoot(), ModalModule.forRoot(), BsDropdownModule.forRoot(), BrowserModule, FormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

*应用程序.组件.ts:

import { Component } from '@angular/core';
import * as moment from 'moment';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'app';
}
export class DemoDropdownBasicLinkComponent {
  public items: string[] = ['The first choice!',
    'And another choice for you.', 'but wait! A third!'];

  public onHidden(): void {
    console.log('Dropdown is hidden');
  }
  public onShown(): void {
    console.log('Dropdown is shown');
  }
  public isOpenChange(): void {
    console.log('Dropdown state is changed');
  }
}
export class DemoButtonsRadioComponent {
  public radioModel: string = 'Middle';
}
export class DemoButtonsBasicComponent {
  public singleModel: string = '1';
}
export class DemoButtonsDisabledComponent {
  public disabled: boolean = true;

}
export class DatepickerDemoComponent {
  public dt: Date = new Date();
  public minDate: Date = void 0;
  public events: any[];
  public tomorrow: Date;
  public afterTomorrow: Date;
  public dateDisabled: {date: Date, mode: string}[];
  public formats: string[] = ['DD-MM-YYYY', 'YYYY/MM/DD', 'DD.MM.YYYY',
    'shortDate'];
  public format: string = this.formats[0];
  public dateOptions: any = {
    formatYear: 'YY',
    startingDay: 1
  };
  private opened: boolean = false;

  public constructor() {
    (this.tomorrow = new Date()).setDate(this.tomorrow.getDate() + 1);
    (this.afterTomorrow = new Date()).setDate(this.tomorrow.getDate() + 2);
    (this.minDate = new Date()).setDate(this.minDate.getDate() - 1000);
    (this.dateDisabled = []);
    this.events = [
      {date: this.tomorrow, status: 'full'},
      {date: this.afterTomorrow, status: 'partially'}
    ];
  }

  public getDate(): number {
    return this.dt && this.dt.getTime() || new Date().getTime();
  }

  public today(): void {
    this.dt = new Date();
  }

  public d20090824(): void {
    this.dt = moment('2009-08-24', 'YYYY-MM-DD')
      .toDate();
  }

  public disableTomorrow(): void {
    this.dateDisabled = [{date: this.tomorrow, mode: 'day'}];
  }

  // todo: implement custom class cases
  public getDayClass(date: any, mode: string): string {
    if (mode === 'day') {
      let dayToCheck = new Date(date).setHours(0, 0, 0, 0);

      for (let event of this.events) {
        let currentDay = new Date(event.date).setHours(0, 0, 0, 0);

        if (dayToCheck === currentDay) {
          return event.status;
        }
      }
    }

    return '';
  }

  public disabled(date: Date, mode: string): boolean {
    return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
  }

  public open(): void {
    this.opened = !this.opened;
  }

  public clear(): void {
    this.dt = void 0;
    this.dateDisabled = undefined;
  }

  public toggleMin(): void {
    this.dt = new Date(this.minDate.valueOf());
  }
}

Angular 的基本规则:模板中使用的所有方法和值都应该位于它所引用的组件中。

在您的情况下,app.component.html 在 AppComponent 中被引用。您指的是您在 DatepickerDemoComponent 中定义的方法。

无论您在 app.component.ts 中导出多少个类,但模板只能访问其顶部具有 @Component 注释的类中的模型和方法。

例如:模板尝试在 AppComponent 类中查找 getDate() 方法,因为它没有任何此类方法,因此会抛出错误。您可以在浏览器控制台中看到它。

尝试移动中定义的所有方法和模型按钮和 DatePicker 组件到应用程序组件。它应该有效。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ngx-bootstrap 日期选择器不起作用 的相关文章

随机推荐

  • Apache POI autoSizeColumn() 无法正常工作[重复]

    这个问题在这里已经有答案了 我正在创建一个程序 使用 apache poi 将信息写入 Excel 文件 将所有数据输入文件后 我对文件的每一列调用 autoSizeColumn 方法 但它会将列的大小调整为最后输入的单元格的宽度 该宽度有
  • LNK1106 具有大量二进制资源

    我的项目中有一个相当大的 dat 文件 896MB 作为 BIN 资源 现在我收到 LNK1106 链接错误 致命错误 LNK1106 无效文件或磁盘已满 无法查找 0x382A3920 我在 Windows XP 下使用 Visual S
  • 用于非图像矩阵的 Keras CNN

    我最近开始学习深度学习和强化学习 我试图弄清楚如何使用 Keras 为 10 行 3 列的 0 和 1 矩阵编写卷积神经网络 例如 输入矩阵看起来像这样 1 0 0 0 1 0 0 0 0 输出应该是另一个由 0 和 1 组成的矩阵 与前面
  • React Native 导航 v5 选项卡按下不起作用

    从代码中可以看出 tabPress 没有被调用 是我做错了还是我遗漏了一些东西 不幸的是我没有找到任何 React 导航版本 5 的代码示例
  • Angular 材质创建类似于引导警报的警报

    我是有角材料的新手 我正在尝试实现警报以使用角度材料显示消息 这与引导警报即类似 div class alert alert success strong Well done strong You successfully read thi
  • 如何在nodejs中验证rabbitmq?

    错误 握手被服务器终止 403 ACCESS REFUSED 消息 ACCESS REFUSED 使用身份验证拒绝登录 旋转机制平原 有关详细信息 请参阅代理日志文件 我单独尝试了 authMechanism PLAIN AMQPLAIN
  • 后台线程c++中的grpc服务器

    我正在尝试在 MFC 应用程序的线程中运行 grpc 服务器 我有 直接来自 GRPC 示例的 grpc 部分 MyAppDlg h include
  • 将项目绑定到 ListBox 的多列中

    我正在尝试将数据添加到多列列表框中 我做到了 但在尝试从列表框中检索数据时遇到了难题 有没有办法将对象而不是文本放入列表框行中
  • Qt 错误:无法打开输出文件调试

    今天我在调试你的程序时 突然因为停电 我的电脑异常关机 现在 当我编译该程序时 它给了我两个错误 1 error cannot open output file debug Myprogram exe Invalid argument 1
  • 艰难地学习 Python:练习 46

    我在设置项目框架时遇到问题 因为现在指南要求我仅使用 Linux 命令 而我使用的是 Windows 整个指南直到该项目与 Windows 没有兼容性问题 直到练习 46 中的一行代码为止 我能够做到这一点 mkdir p projects
  • 如何在Play Framework中手动抛出错误页面?

    如何手动抛出404 or 500Play 框架 1 2 x 中出现错误 我目前正在渲染404 html and 500 html模板使用renderTemplate 方法 但我该如何以正确的方式做到这一点呢 Play Controller
  • Eclipse CDT 索引器是否仅限于源和标头的常见文件类型?

    我正在开发一个涉及 TOM 文件 t 扩展名 的项目 这些文件被编译成 c 文件 现在 我已经告诉我的 Eclipse 将它们视为 C 源文件 但 CDT 索引器似乎不想触及它们 是否可以告诉它考虑其他文件类型 注意 TOM 文件看起来就像
  • 绘制两个不同长度的列表

    我有两个价格不同的清单 第一个列表是 2008 2018 年 第二个列表是 2010 2018 年 如果 X 轴为 2008 年至 2018 年 第二个列表从 2010 年开始 我如何绘制它们 我有以下作为简短代码的示例 from matp
  • 如何在 Spring MVC (JPA) 中将实体对象列表转换为页面对象?

    我有一个List的实体 我如何将其转换为Page使用 Spring MVC 4 和 Spring Data JPA 的对象 有一个Page执行 http docs spring io spring data commons docs cur
  • 导航控制器后退按钮可转到上一屏幕之前的屏幕

    我想知道是否可以使用导航控制器按钮返回到上一页 现在 我已经使用此代码定制了按钮 self navigationItem leftBarButtonItem UIBarButtonItem alloc initWithTitle mainL
  • 如何在 R 中将度分秒转换为十进制?

    我有这个数据框 Lat Long 59 44 50 151 45 11 59 49 28 154 52 56 59 46 42 150 45 15 如何将其转换为十进制列 纬度的单位为 dd mm ss 长的单位为 ddd mm ss 我在
  • 如何使用 JSONata 将嵌套对象展平为单深度对象?

    我是 JSONata 新手 在创建展平函数时遇到一些麻烦 我想把这个输入 user key value map CreatedDate 123424 Department Name XYZ 进入这个 user key value map C
  • 在 OpenCV 中使用 FindExtrinsicCameraParams2

    我在对象坐标和相应的图像点 在图像平面上 中有 4 个共面点 我想计算物平面相对于相机的相对平移和旋转 FindExtrinsicCameraParams2 应该是解决方案 但我在使用它时遇到了麻烦 编译时不断出现错误 有人在OpenCV中
  • 显示 WordPress 中最新的搜索词

    有没有办法显示我网站上最近完成的搜索词 我想显示访问者最近执行的 3 5 个搜索词 以便鼓励其他用户也搜索某些内容 Edit 在这种情况下 如果有人搜索新内容 刷新页面可能会显示一组新的搜索词 我确信至少有一些插件可以帮助您解决此问题 我会
  • ngx-bootstrap 日期选择器不起作用

    我正在学习 Angular2 和 Bootstrap4 我的公司使用以下网站 http valor software com ngx bootstrap datepicker http valor software com ngx boot