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

相关内容

热门资讯

透视好牌"竞技联盟破... 此外,数据分析德州(竞技联盟破解版最新版)辅助神器app还具备辅助透视行为开挂功能,通过对客户竞技联...
攻略讲解!拱趴大菠萝怎么开挂,... 攻略讲解!拱趴大菠萝怎么开挂,德普之星透视辅助软件激活码,靠谱教程(有挂透明);《WPK辅助透视》‌...
透视苹果版"wepo... 透视苹果版"wepoker怎么设置透视"详细辅助新2025教程(从来存在有挂)1、许多玩家不知道we...
一分钟秒懂!wepoker祈福... 1、一分钟秒懂!wepoker祈福有用吗,pokemmo手机脚本辅助器,曝光教程(有挂方法)。2、p...
透视真的"wepok... 透视真的"wepoker辅助器安装包定制"详细辅助2025版教程(确实是有挂);支持2-10人实时对...
教学盘点!wepokerplu... 教学盘点!wepokerplus脚本,wepoker游戏的安装教程,安装教程(有挂神器)是一款可以让...
透视好友房"约局吧德... 透视好友房"约局吧德州有挂吗"详细辅助攻略教程(果然有挂);约局吧德州有挂吗软件透明挂作为一款约局吧...
总算清楚!hhpoker到底可... 总算清楚!hhpoker到底可以作弊码,pokemmo手机脚本辅助器,安装教程(有挂软件)是一款可以...
透视规律"wepok... 透视规律"wepoker辅助器下载"详细辅助辅助教程(原先是有挂),支持语音通讯、好友开房及战队组建...
科技通报!wpk透视是真的假的... 1、科技通报!wpk透视是真的假的,wepoker透视脚本是什么,攻略教程(有挂技巧)。2、wepo...