当我使用angular4建立网站时,我需要使用 ng-bootstrap 组件作为日期选择器,但出现了一个问题: 这是我的代码: 我的代码有什么问题!
import { Component, OnInit } from '@angular/core';
import { JhiLanguageService } from 'ng-jhipster';
import { Principal, AccountService, JhiLanguageHelper } from 'app/core';
import { SettingsService } from 'app/account/settings/settings.service';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import {NgbDateStruct, NgbDateAdapter, NgbDate, NgbCalendar} from '@ng-bootstrap/ng-bootstrap';
import { Moment } from "moment";
import { User} from "app/core";
@Component({
selector: 'jhi-settings',
templateUrl: './settings.component.html',
styleUrls: ['settings.css']
})
export class SettingsComponent implements OnInit {
error: string;
success: string;
settingsAccount: any;
languages: any[];
genders: [];
levels: [];
avatarFileName: string;
avatarFile: File;
mydob= {year: 2018, month: 9, day: 15};
constructor(
private account: AccountService,
private principal: Principal,
private languageService: JhiLanguageService,
private languageHelper: JhiLanguageHelper,
private settingService: SettingsService,
private today : NgbCalendar
) { }
}
日期 出生
答案 0 :(得分:2)
您必须导入以下时刻:
import * as moment from "moment";
在组件中按如下所示设置mydob
,maxDate
和minDate
值之后:
minDate = moment({year: 1990, month: 1, day : 1});
maxDate = moment({year: 2018, month: 9, day : 13});
mydob = moment({year: 2018, month: 9, day: 15});
并在下面的HTML输入中使用:
<input class="form-control dob" placeholder="enter your birth" name="dob" id="dob" readonly (click)="d.toggle()" [maxDate]="maxDate" [minDate]="minDate" required name="dob" [(ngModel)]="mydob" ngbDatepicker #d="ngbDatepicker">