我想写关于 Angular 的 datepicker 我想写日期验证以便不选择下一个日期 角度示例:今天是日期 17/12/2020 你可以选择日期 17 或 16 或超过 17 但你不能选择日期 18 或不到 17 岁。我想知道如何用 Angular 书写
.html 文件:
<div class="form-group col-md-6">
<label for="date">Date</label>
<input type="date" formControlName="date" class="form-control" id="date" placeholder="date">
</div>
add-ticket.component.ts 文件
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { Component, OnInit } from '@angular/core';
import { TicketService } from 'src/app/services/ticket/ticket.service';
import Swal from 'sweetalert2/dist/sweetalert2.js';
@Component({
selector: 'app-add-ticket',
templateUrl: './add-ticket.component.html',
styleUrls: ['./add-ticket.component.scss']
})
export class AddTicketComponent implements OnInit {
public addTicketForm: FormGroup;
constructor(
public ticketService: TicketService,
public fb: FormBuilder
) { }
ngOnInit() {
this.ticketService.getTicketsList();
this.buildForm();
}
successNotification(){
Swal.fire({
text: 'Your ticket has been saved',
icon: 'success',
}).then((result) => {
window.location.href = "./../ticket";
})
}
sources = [
{ name: 'website' },
{ name: 'Facebook' },
{ name: 'Line' },
{ name: 'Email' },
{ name: 'Telephone' },
{ name: 'Onsite' }
]
types = [
{ name: 'info' },
{ name: 'consult' },
{ name: 'problem' },
{ name: 'add-ons' }
]
prioritys = [
{ name: 'low' },
{ name: 'medium' },
{ name: 'high' }
]
buildForm() {
this.addTicketForm = this.fb.group({
date: [''],
source: [''],
siteName: ['', [Validators.required]],
maintenancePackage: ['', [Validators.required]],
product: ['', [Validators.required]],
module: [''],
creater: ['', [Validators.required]],
type: [''],
subject: ['', [Validators.required]],
priority: [''],
description: [''],
resolveDescription: [''],
})
}
get date() {
return this.addTicketForm.get('date');
}
get source() {
return this.addTicketForm.get('source');
}
get siteName() {
return this.addTicketForm.get('siteName');
}
get maintenancePackage() {
return this.addTicketForm.get('maintenancePackage');
}
get product() {
return this.addTicketForm.get('product');
}
get module() {
return this.addTicketForm.get('module');
}
get creater() {
return this.addTicketForm.get('creater');
}
get type() {
return this.addTicketForm.get('type');
}
get subject() {
return this.addTicketForm.get('subject');
}
get priority() {
return this.addTicketForm.get('priority');
}
get description() {
return this.addTicketForm.get('description');
}
get resolveDescription() {
return this.addTicketForm.get('resolveDescription');
}
addTicketData() {
this.ticketService.addTicket(this.addTicketForm.value);
}
}