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

相关内容

热门资讯

透视必备!hhpoker免费辅... 透视必备!hhpoker免费辅助器,hhpoker真的有透视吗-一直有辅助app(哔哩哔哩)小薇(辅...
透视了解!wpk官网下载链接,... 透视了解!wpk官网下载链接,wpk辅助-真是一直总是有辅助技巧(哔哩哔哩)1、任何透视是真的假的的...
透视必备!wepoker有没有... 透视必备!wepoker有没有辅助,wepoker怎么获得好牌-一贯是有辅助技巧(哔哩哔哩)1)免费...
透视揭幕!we-poker是什... 透视揭幕!we-poker是什么软件,wejoker辅助机器人-都是一直总是有辅助工具(哔哩哔哩)透...
透视总结!wepoker辅助脚... 透视总结!wepoker辅助脚本,wepoker怎么设置盖牌-确实是真的有辅助攻略(哔哩哔哩)1、该...
透视必备!wpk俱乐部辅助器,... 透视必备!wpk俱乐部辅助器,wpk俱乐部怎么作弊-都是一直总是有辅助app(哔哩哔哩);1、完成辅...
透视解谜!wpk德州局怎么透视... 透视解谜!wpk德州局怎么透视,wpk透视辅助靠谱吗-切实有辅助方法(哔哩哔哩)德州局怎么透视破解侠...
透视揭露!wepoker模拟器... 透视揭露!wepoker模拟器哪个,we-poker靠谱吗-竟然存在有辅助神器(哔哩哔哩)在进入软件...
透视辅助!hhpoker有没有... 透视辅助!hhpoker有没有作弊辅助,hhpoker是内部控制吗-总是是有辅助软件(哔哩哔哩)1、...
透视普及!aapoker透视插... 透视普及!aapoker透视插件,aapoker万能辅助器-好像一直总是有辅助神器(哔哩哔哩)一、可...