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

相关内容

热门资讯

一分钟辅助!钱塘十三水脚本,原... 一分钟辅助!钱塘十三水脚本,原来有辅助脚本(有挂助手)1、钱塘十三水脚本破解器简单,钱塘十三水脚本机...
第九分钟辅助!丽水茶苑苹果手机... 第九分钟辅助!丽水茶苑苹果手机辅助,切实是真的有辅助挂(有挂透视)丽水茶苑苹果手机辅助是不是有人用挂...
四分钟辅助!广东雀神智能插件官... 四分钟辅助!广东雀神智能插件官网,原来真的有辅助技巧(有挂详情)进入游戏-大厅左侧-新手福利-激活码...
一分钟辅助!闲逸碰胡外桂,其实... 一分钟辅助!闲逸碰胡外桂,其实是有辅助教程(有挂存在)1、闲逸碰胡外桂破解器简单,闲逸碰胡外桂机器人...
8分钟辅助!创思维app有挂吗... 8分钟辅助!创思维app有挂吗,果然是有辅助教程(竟然有挂)1、金币登录送、破产送、升级送、活动送。...
第8分钟辅助!中至余干如何破解... 第8分钟辅助!中至余干如何破解,本来真的是有辅助app(有人有挂)小薇(辅助器软件下载)致您一封信;...
第二分钟辅助!518互游私人定... 第二分钟辅助!518互游私人定制,确实是有辅助攻略(有挂透视)第二分钟辅助!518互游私人定制,确实...
第七分钟辅助!三七互娱辅助器透... 第七分钟辅助!三七互娱辅助器透视开挂,总是是真的有辅助器(有人有挂)1、三七互娱辅助器透视开挂公共底...
第九分钟辅助!微乐小程序黑科技... 第九分钟辅助!微乐小程序黑科技app入口,果然有辅助软件(有挂讲解)一、微乐小程序黑科技app入口可...
4分钟辅助!广东雀神智能插件安... 4分钟辅助!广东雀神智能插件安装辅助器,都是是真的有辅助挂(新版有挂)进入游戏-大厅左侧-新手福利-...