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

相关内容

热门资讯

第6分钟外挂!微信多乐跑辅助,... 第6分钟外挂!微信多乐跑辅助,天天微友有辅助吗,规律教程(确实有挂)-哔哩哔哩1、天天微友有辅助吗系...
第六分钟外挂!南通长牌辅助器插... 第六分钟外挂!南通长牌辅助器插件,八闽福建辅助,攻略方法(有挂秘笈)-哔哩哔哩运南通长牌辅助器插件辅...
第5分钟外挂!四川游戏家园破解... 第5分钟外挂!四川游戏家园破解版,顺欣茶楼开挂,实用技巧(真是有挂)-哔哩哔哩1)四川游戏家园破解版...
第1分钟外挂!欢乐对决破解版,... 第1分钟外挂!欢乐对决破解版,友友联盟辅助器,可靠教程(有挂教学)-哔哩哔哩1)友友联盟辅助器辅助挂...
4分钟外挂!朋朋政和辅助器免费... 4分钟外挂!朋朋政和辅助器免费在哪里,心悦手游辅助,必赢教程(有挂辅助)-哔哩哔哩进入游戏-大厅左侧...
第七分钟外挂!边锋游戏小程序辅... 第七分钟外挂!边锋游戏小程序辅助器免费,大菠萝免费辅助,2025新版(确实有挂)-哔哩哔哩1、第七分...
一分钟外挂!越乡有辅助软件,永... 一分钟外挂!越乡有辅助软件,永胜联盟辅助器,教你攻略(讲解有挂)-哔哩哔哩1、让任何用户在无需永胜联...
六分钟外挂!圣盛荆州晃晃辅助工... 六分钟外挂!圣盛荆州晃晃辅助工具,新玄龙辅助,插件教程(有挂细节)-哔哩哔哩一、圣盛荆州晃晃辅助工具...
第8分钟外挂!丽水都来大菠萝脚... 第8分钟外挂!丽水都来大菠萝脚本辅助,wepoker开挂事件,安装教程(有挂头条)-哔哩哔哩1)丽水...
第9分钟外挂!奇迹陕西麻将辅助... 第9分钟外挂!奇迹陕西麻将辅助器,越乡游辅助工具,教你攻略(讲解有挂)-哔哩哔哩该软件可以轻松地帮助...