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私人辅助,wp... 透视真的!wpk私人辅助,wpk透视辅助靠谱吗,微扑克教程(原来真的有挂)1、wpk透视辅助靠谱吗a...
透视透视!wepoker透视脚... 透视透视!wepoker透视脚本,wepoker有辅助器吗(切实存在有挂)1、完成wepoker有辅...
透视新版!wpk透视插件,wp... 透视新版!wpk透视插件,wpk刷入池率脚本,AI教程(一直是有挂);亲,关键说明,wpk刷入池率脚...
透视ai代打!wepoker透... 透视ai代打!wepoker透视脚本是什么,wepoker有什么规律(都是真的是有挂)wepoker...
透视美元局!wepoker底牌... 透视美元局!wepoker底牌透视,wepoker透视辅助下载(真是真的是有挂)1、wepoker透...
透视好牌!wpk作弊,wpk私... 透视好牌!wpk作弊,wpk私人局辅助是真的吗,必赢教程(都是真的是有挂);wpk私人局辅助是真的吗...
透视游戏!wepoker透视器... 透视游戏!wepoker透视器免费,安装不了wepoker(总是是真的有挂)1、每一步都需要思考,不...
透视有挂!wpk辅助购买,wp... 透视有挂!wpk辅助购买,wpk显示有作弊,微扑克教程(原来是有挂);wpk显示有作弊辅助器中分为三...
透视科技!we-poker是什... 透视科技!we-poker是什么软件,we-poker辅助(竟然是真的有挂)1、让任何用户在无需we...
透视插件!wpk私人局辅助是真... 透视插件!wpk私人局辅助是真的吗,wpk有那种辅助吗,必胜教程(都是是有挂);在进入wpk私人局辅...