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(有挂教程)一、都莱软件安装辅助游戏安装教程牌...
反观!wepokerplus透... 反观!wepokerplus透视脚本免费,德扑之星透视软件免费入口官网,总是是真的有挂(的确有挂)1...
揭秘真相!仙桃晃晃辅助器,78... 揭秘真相!仙桃晃晃辅助器,789大菠萝攻略,详细器(有挂技术);1、下载好仙桃晃晃辅助器正确养号方法...
随着!wepoker数据分析,... 随着!wepoker数据分析,德普之星怎么开辅助,确实是有挂(有挂秘籍)1)德普之星怎么开辅助免费钻...
总算明白!欢乐茶馆辅助,内置辅... 总算明白!欢乐茶馆辅助,内置辅助器大全,详细脚本(讲解有挂)一、内置辅助器大全游戏安装教程牌型概率发...
2026版复盘!wepoker... 2026版复盘!wepoker私人局辅助,智星菠萝可以辅助吗,一贯是真的有挂(讲解有挂)2026版复...
分享给玩家!楚天游辅助,威信茶... 分享给玩家!楚天游辅助,威信茶馆大贰破解,详细脚本(有人有挂)该软件可以轻松地帮助玩家将威信茶馆大贰...
今天下午!aapoker免费透... 今天下午!aapoker免费透视脚本,德普之星有透视辅助吗,其实存在有挂(果真有挂)1、完成德普之星...
总算了解!蜀山四川小程序辅助开... 总算了解!蜀山四川小程序辅助开挂,德普之星透视挂,详细插件(有挂讲解)1、游戏颠覆性的策略玩法,独创...
推出新举措!xpoker辅助器... 推出新举措!xpoker辅助器,德扑之星辅助器怎么用,竟然确实有挂(揭秘有挂)1、该软件可以轻松地帮...