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

相关内容

热门资讯

透视好友房"poke... 透视好友房"pokerworld软件"详细辅助微扑克教程(透视器免费神器)1、玩家可以在pokerw...
透视真的"fishp... 透视真的"fishpoker透视底牌"详细辅助详细教程(透视有用神器);人气非常高,ai更新快且高清...
透视实锤"哈糖大菠萝... 透视实锤"哈糖大菠萝万能挂"详细辅助安装教程(辅助器免费安装软件)是一款可以让一直输的玩家,快速成为...
透视透视挂"德州透视... 透视透视挂"德州透视是真的吗"详细辅助揭秘教程(有人用过技巧)准备好在德州透视是真的吗 ia的高塔上...
透视挂"poker红... 透视挂"poker红龙辅助"详细辅助2025新版(正确养号方法辅助)准备好在poker红龙辅助 ia...
透视ai"wpk辅助... 透视ai"wpk辅助插件"详细辅助必胜教程(手机插件软件);原来确实真的有挂(需添加指定薇13670...
透视数据"德普之星怎... 透视数据"德普之星怎么设置埋牌"详细辅助存在挂教程(到底是挂了辅助);原来确实真的有挂(需添加指定薇...
辅助透视"wepok... 辅助透视"wepokerh5破解"详细辅助必赢教程(辅助工具技巧);人气非常高,ai更新快且高清可以...
透视中牌率"htx矩... 透视中牌率"htx矩阵wepoker辅助"详细辅助透视教程(私人局透视技巧)是一款可以让一直输的玩家...
透视能赢"wepok... 透视能赢"wepoker科技辅助器"详细辅助AA德州教程(辅助器透明);玩家必备必赢加哟《13670...