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

相关内容

热门资讯

透视秘籍!uupoker有透视... 透视秘籍!uupoker有透视吗(AApoker俱乐部)本来是有辅助软件(哔哩哔哩)1、uupoke...
透视妙计!wepoker辅助透... 透视妙计!wepoker辅助透视软件(WePoKer看底牌)一直真的是有辅助教程(哔哩哔哩)该软件可...
透视阶段!pokernow辅助... 透视阶段!pokernow辅助控制(WePoKer教程)总是真的是有辅助脚本(哔哩哔哩)1、全新机制...
透视妙计!aapoker怎么拿... 透视妙计!aapoker怎么拿好牌(WePoKer黑科技)一贯是真的有辅助软件(哔哩哔哩)1、aap...
透视步骤!wpk辅助软件(We... 透视步骤!wpk辅助软件(WePoKer开辅助)真是是有辅助方法(哔哩哔哩)1、点击下载安装,wpk...
透视步骤!约局吧app有挂吗(... 透视步骤!约局吧app有挂吗(WePoKer养号)果然是真的有辅助神器(哔哩哔哩)1、完成约局吧ap...
透视妙招!wepoker透视脚... 透视妙招!wepoker透视脚本网页(WePoKer软件)一贯存在有辅助脚本(哔哩哔哩)所有人都在同...
透视操作!wejoker免费脚... 透视操作!wejoker免费脚本(AApoker方法)真是是真的有辅助脚本(哔哩哔哩)小薇(辅助器软...
透视指引!wepoker有没有... 透视指引!wepoker有没有挂(WePoKer钻石)确实真的有辅助脚本(哔哩哔哩)1)wepoke...
透视策略!hhpoker软件可... 透视策略!hhpoker软件可以玩吗(AApoker安装包)一直真的有辅助软件(哔哩哔哩)hhpok...