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模板中:

相关内容

热门资讯

受玩家影响!新荣耀辅助安装&q... 受玩家影响!新荣耀辅助安装"辅助辅助软件"确实存在有挂(哔哩哔哩)新荣耀辅助安装脚本下载中分为三种模...
于此同时!旺旺福建麻将辅助器&... 于此同时!旺旺福建麻将辅助器"专业辅助挂"本来是有挂(哔哩哔哩)1、用户打开应用后不用登录就可以直接...
透视辅助!新樱花互娱源码&qu... 透视辅助!新樱花互娱源码"教你辅助神器"原来存在有挂(哔哩哔哩)1、完成新樱花互娱源码有辅助插件,帮...
透视玄学!潮汕暗宝辅助透视&q... 透视玄学!潮汕暗宝辅助透视"有挂辅助方法"其实是真的有挂(哔哩哔哩)潮汕暗宝辅助透视脚本下载中分为三...
今天下午!填大坑辅助器&quo... 今天下午!填大坑辅助器"必备辅助攻略"一直确实有挂(哔哩哔哩)1、每一步都需要思考,不同水平的挑战填...
据悉!中至小程序如何破解&qu... 据悉!中至小程序如何破解"透视辅助工具"好像真的是有挂(哔哩哔哩)中至小程序如何破解脚本下载中分为三...
透视辅助!闲来游戏辅助软件&q... 透视辅助!闲来游戏辅助软件"专业辅助教程"好像真的有挂(哔哩哔哩)1、金币登录送、破产送、升级送、活...
透视透视!扣点点脚本辅助器&q... 透视透视!扣点点脚本辅助器"揭幕辅助方法"总是真的是有挂(哔哩哔哩)扣点点脚本辅助器脚本下载中分为三...
据了解!九游辅助器"... 据了解!九游辅助器"详细辅助工具"竟然存在有挂(哔哩哔哩)暗藏猫腻,小编详细说明九游辅助器破解器有用...
总结辅助挂!巴蜀长牌辅助&qu... 总结辅助挂!巴蜀长牌辅助"详细辅助器"原来是有挂(哔哩哔哩)1、巴蜀长牌辅助免费脚本咨询教程、巴蜀长...