Angular2 Ng日期时间选择器在打开时太大

时间:2018-07-14 07:30:43

标签: angular datetimepicker

我将Ng日期时间选择器与Angular2前端结合使用,来自: https://danielykpan.github.io/date-time-picker/?utm_source=recordnotfound.com 我尝试从此处复制并粘贴示例: https://stackblitz.com/github/DanielYKPan/owl-examples/tree/date-time-picker?file=src%2Fmain.ts

进入我的组件html文件。我正在使用ngx-admin模板。

但是,当我启动组件并在输入字段中单击以打开日期选择器时,布局有点“混乱”,并且在左侧的窗口上太大了(请参见屏幕截图):

Datepicker too big (left side)

但是我在代码中没有看到任何错误...这是我的模板:

 <label class="example-input-wrapper">
    Date Time:
    <input placeholder="Date Time:"
           [(ngModel)]="dateTime"
           [owlDateTimeTrigger]="dt" [owlDateTime]="dt">
    <owl-date-time #dt></owl-date-time>
</label>

component.ts:

public dateTime: Date;

app.module.ts:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FlexibilitiesComponent } from './flexibilities.component';
import { ThemeModule } from '../../@theme/theme.module';
import { NgxEchartsModule } from "ngx-echarts";
import { NgxChartsModule } from '@swimlane/ngx-charts';
import { DlDateTimePickerDateModule } from 'angular-bootstrap-datetimepicker';
import { AngularDateTimePickerModule } from 'angular2-datetimepicker';
import { NguiDatetimePickerModule } from '@ngui/datetime-picker';
import { OwlDateTimeModule, OwlNativeDateTimeModule } from 'ng-pick-datetime';
import { MomentModule } from 'angular2-moment';


@NgModule({
  imports: [
    CommonModule,
    ThemeModule,
    NgxEchartsModule,
    NgxChartsModule,
    DlDateTimePickerDateModule,
    AngularDateTimePickerModule,
    NguiDatetimePickerModule,
    OwlDateTimeModule,
    OwlNativeDateTimeModule,
    MomentModule,
  ],
  declarations: [FlexibilitiesComponent] 
})
export class FlexibilitiesModule { }

在stackblitz,他们使用了更多的模块,但是我不知道它们是特定于应用程序还是需要运行日期时间选择器...:

import { BasicComponent } from './basic/basic.component';
import { StandAloneComponent } from './stand-alone/stand-alone.component';
import { RangeComponent } from './range/range.component';
import { StartViewComponent } from './start-view/start-view.component';
import { ValidationComponent } from './validation/validation.component';
import { RestrictionComponent } from './restriction/restriction.component';
import { LocalizationComponent } from './localization/localization.component';
import { MomentJsComponent } from './moment-js/moment-js.component';

有什么想法可以解决这个问题吗?

2 个答案:

答案 0 :(得分:3)

尝试以下解决方案:

在style.scss中添加@import "~ng-pick-datetime/assets/style/picker.min.css";

答案 1 :(得分:0)

添加@import "~ng-pick-datetime/assets/style/picker.min.css";

src文件夹的styles.scss中

如果没有这个,可以在angular.json中定义它

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    ...
      "architect": {
        "build": {
          ...
            "styles": [
              "src/styles.scss",
              "node_modules/bootstrap/dist/css/bootstrap.min.css"
           ]}
            ...
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.scss"
            ],
            ...
}