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

相关内容

热门资讯

透视教程!wpk透视最怕三个东... 透视教程!wpk透视最怕三个东西(透视)wpk透视怎么安装-果然真的是有挂(哔哩哔哩)1、完成wpk...
2026版辅助挂!wpk透视是... 2026版辅助挂!wpk透视是真的吗(透视)wpk有那种辅助吗-确实是有挂(哔哩哔哩)1、下载好wp...
透视安卓版!智星德州插件最新版... 透视安卓版!智星德州插件最新版本更新内容详解(透视)智星德州可以透视吗-切实是有挂(哔哩哔哩)小薇(...
透视真的!德普软件(透视)德普... 透视真的!德普软件(透视)德普之星透视辅助软件-竟然真的有挂(哔哩哔哩)1、游戏颠覆性的策略玩法,独...
透视中牌率!aapoker透视... 透视中牌率!aapoker透视插件(透视)hhpoker德州牛仔视频-其实是有挂(哔哩哔哩)暗藏猫腻...
透视代打!aapoker真的假... 透视代打!aapoker真的假的(透视)hhpoker辅助挂-原来有挂(哔哩哔哩)1、下载好aapo...
长期以来!hhpoker免费透... 长期以来!hhpoker免费透视脚本(透视)hhpoker透视实战视频-其实真的是有挂(哔哩哔哩)1...
据相关数据显示!aapoker... 据相关数据显示!aapoker脚本怎么用(透视)hhpoker俱乐部是干嘛的-都是是有挂(哔哩哔哩)...
复盘辅助挂!购买的wpk辅助在... 复盘辅助挂!购买的wpk辅助在哪里下载(透视)wpk模拟器是什么-原来是有挂(哔哩哔哩);1、购买的...
透视辅助!德普辅助软件(透视)... 透视辅助!德普辅助软件(透视)德普之星透视软件免费入口官网-果然存在有挂(哔哩哔哩)1、完成德普之星...