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

相关内容

热门资讯

9分钟教材!wpk控制牌是真的... 9分钟教材!wpk控制牌是真的吗(透视)总是真的是有辅助开挂(哔哩哔哩)1、玩家可以在wpk控制牌是...
第三分钟脚本!微信小程序小南四... 第三分钟脚本!微信小程序小南四川长牌辅助,麻雀智能辅助软件(好像有挂辅助软件)-哔哩哔哩1、点击下载...
九分钟讲义!约局吧能不能开挂(... 九分钟讲义!约局吧能不能开挂(透视)果然真的有辅助下载(哔哩哔哩)1、约局吧能不能开挂透视辅助软件激...
第十分钟辅助!禅游指尖四川修改... 第十分钟辅助!禅游指尖四川修改器,好友赣南能装挂吗(都是真的有辅助插件)-哔哩哔哩禅游指尖四川修改器...
第1分钟总结!xpoker辅助... 第1分钟总结!xpoker辅助工具(透视)一直是有辅助神器(哔哩哔哩)1、完成xpoker辅助工具辅...
七分钟辅助!广西八一透明最新款... 七分钟辅助!广西八一透明最新款,道游互娱辅助(总是真的有辅助app)-哔哩哔哩1)广西八一透明最新款...
第一分钟总结!wepoker私... 第一分钟总结!wepoker私人局可以透视(透视)其实是有辅助开挂(哔哩哔哩)1、wepoker私人...
第7分钟插件!贰柒拾辅助软件是... 第7分钟插件!贰柒拾辅助软件是真的吗,麻友圈安庆版插件(真是是有辅助工具)-哔哩哔哩所有人都在同一条...
第5分钟安装!大唐麻将辅助软件... 第5分钟安装!大唐麻将辅助软件,哥哥打大a辅助(切实存在有辅助插件)-哔哩哔哩1、每一步都需要思考,...
第三分钟步骤!约局吧是否有挂(... 第三分钟步骤!约局吧是否有挂(透视)一贯有辅助工具(哔哩哔哩)1、打开软件启动之后找到中间准星的标志...