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作必弊是真的吗... 透视经验!wpk作必弊是真的吗,拱趴大菠萝万能挂图解(透视)本来有挂(哔哩哔哩)1、金币登录送、破产...
透视窍要!如何判断wpk辅助软... 透视窍要!如何判断wpk辅助软件的真假,wpk有那种辅助吗(透视)都是是真的透视方法(哔哩哔哩)1、...
透视模板!德州私人局脚本,we... 透视模板!德州私人局脚本,wepoker免费辅助器(透视)果然有挂(哔哩哔哩)1、每一步都需要思考,...
透视妙计!wepoker怎么挂... 透视妙计!wepoker怎么挂飞机,wepokerplus作必弊(透视)一贯有脚本技巧(哔哩哔哩)1...
透视积累!wepoker轻量版... 透视积累!wepoker轻量版透视,wepoker辅助器免费(透视)其实有挂(哔哩哔哩);1、每一步...
透视模块!aapoker破解侠... 透视模块!aapoker破解侠是真的吗,aapoker透视脚本下载(透视)一直存在有脚本方法(哔哩哔...
透视项目!hhpoker有后台... 透视项目!hhpoker有后台操控吗,竞技联盟透视插件(透视)果然真的是有挂(哔哩哔哩)1.hhpo...
透视窍要!购买的wpk辅助在哪... 透视窍要!购买的wpk辅助在哪里下载,wpk辅助插件(透视)原来真的有脚本脚本(哔哩哔哩)1、不需要...
透视操作!wepoker公共底... 透视操作!wepoker公共底牌,wpk透视插件(透视)好像是真的挂(哔哩哔哩)1、许多玩家不知道w...
透视窍门!hhpoker外开挂... 透视窍门!hhpoker外开挂靠谱吗,hhpoker辅助挂(透视)都是真的是有脚本软件(哔哩哔哩)1...