Angular日期选择器模式不如预期的出现。
创始人
2024-10-29 05:30:42
0

在模板上添加一个按钮,点击按钮时打开模态对话框。使用ngModel绑定来获取所选日期。以下是可用的代码示例:

在模板上添加的按钮:

在组件.ts文件中:

import { Component } from '@angular/core'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

@Component({ selector: 'app-datepicker', template: '', styleUrls: ['./datepicker.component.css'] }) export class DatepickerComponent {

selectedDate: any;

constructor(private modalService: NgbModal) { }

openDatePicker() {
    const modalRef = this.modalService.open(NgbdModalContent);
    modalRef.componentInstance.data = { selectedDate: this.selectedDate };
    modalRef.result.then((result) => {
        if (result !== undefined) {
            this.selectedDate = result;
        }
    }, (reason) => {
        console.log(reason);
    });
}

}

在模态对话框组件中:

import { Component, Input } from '@angular/core'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

@Component({ selector: 'ngbd-modal-content', templateUrl: './modal-content.component.html' }) export class NgbdModalContent { @Input() data;

constructor(private activeModal: NgbActiveModal) { }

get selectedDate() {
    return this.data.selectedDate;
}

set selectedDate(date: any) {
    this.data.selectedDate = date;
}

closeModal() {
    this.activeModal.close(this.selectedDate);
}

}

在模态对话框组件的HTML模板中:

相关内容

热门资讯

1分钟了解(线上德州aapok... 1分钟了解(线上德州aapoker)外挂透明挂辅助神器(透视)2025新版总结(2024已更新)(哔...
两分钟了解(德扑之星埋牌)黑科... 两分钟了解(德扑之星埋牌)黑科技透明挂辅助下载(透视)透明教程(2023已更新)(哔哩哔哩)是一款可...
十分钟了解(wePOKE)软件... 十分钟了解(wePOKE)软件透明挂辅助软件(透视)透明挂教程(2024已更新)(哔哩哔哩)是一款可...
9分钟了解(微扑克技术)软件透... 您好,微扑克技术这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款游...
1分钟了解(Wepoke数据)... 1分钟了解(Wepoke数据)外挂智能ai辅助黑科技(透视)曝光教程(2026已更新)(哔哩哔哩);...
9分钟了解(智星德州)软件透明... 9分钟了解(智星德州)软件透明挂辅助工具(透视)切实教程(2024已更新)(哔哩哔哩);一、智星德州...
第2分钟了解(Wepoke必备... 第2分钟了解(Wepoke必备)黑科技透明挂辅助下载(透视)力荐教程(2020已更新)(哔哩哔哩)是...
八分钟了解(Wepoke私人局... 八分钟了解(Wepoke私人局)外挂智能ai辅助下载(透视)详细教程(2026已更新)(哔哩哔哩)是...
第二分钟了解(德扑之星app)... 第二分钟了解(德扑之星app)软件透明挂辅助安装(透视)AI教程(2021已更新)(哔哩哔哩)是一款...
八分钟了解(德州ai智能)黑科... 八分钟了解(德州ai智能)黑科技透明挂辅助工具(透视)扑克教程(2024已更新)(哔哩哔哩)是一款可...