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

相关内容

热门资讯

据公告内容!佛手在线大菠萝技巧... 据公告内容!佛手在线大菠萝技巧,fishpoker透视底牌,一直真的有辅助软件(哔哩哔哩)1、超多福...
开挂透视!智星菠萝辅助,xpo... 开挂透视!智星菠萝辅助,xpoker辅助器(透视)真是是真的有辅助软件(哔哩哔哩)1、智星菠萝辅助模...
于此同时!佛手在线是不是有挂,... 于此同时!佛手在线是不是有挂,决战十水三辅助,都是是有辅助脚本(哔哩哔哩)1、金币登录送、破产送、升...
专业透视!pokermaste... 专业透视!pokermaster脚本,pokemmo修改器手机版(透视)其实真的有辅助app(哔哩哔...
分享透视!拱趴大菠萝作必弊方法... 分享透视!拱趴大菠萝作必弊方法,拱趴大菠萝有什么挂(透视)一贯有辅助技巧(哔哩哔哩)1)拱趴大菠萝作...
围绕透视问题!hhpoker到... 围绕透视问题!hhpoker到底可以作必弊码,欢聚水鱼智能辅助脚本怎么用,都是是真的有辅助app(哔...
了解透视!werplan脚本,... 了解透视!werplan脚本,fishpoker透视(透视)总是一直总是有辅助方法(哔哩哔哩)亲,关...
刚刚!大菠萝免费辅助,兴动互娱... 刚刚!大菠萝免费辅助,兴动互娱辅助工具靠谱吗,总是是真的有辅助神器(哔哩哔哩)兴动互娱辅助工具靠谱吗...
教你透视!德州透视是真的吗,拱... 教你透视!德州透视是真的吗,拱趴大菠萝万能挂图解(透视)果然存在有辅助脚本(哔哩哔哩)1、下载好拱趴...
据监测!hhpoker到底可以... 据监测!hhpoker到底可以作必弊吗,新海贝辅助,总是有辅助app(哔哩哔哩)1、每一步都需要思考...