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

相关内容

热门资讯

终于知道!wepoker模拟器... 终于知道!wepoker模拟器哪个好用,wpk透视工作室,科技教程(有挂技巧);科技安装教程;136...
交流学习经验!wepoker辅... 交流学习经验!wepoker辅助器软件下载,wepoker软件安装包,我来教教你(有挂技巧);原来确...
一分钟了解!哈糖大菠萝有挂吗5... 一分钟了解!哈糖大菠萝有挂吗5个常用方法,wepoker一直输的号能继续打吗,教你攻略(有挂教程)这...
必看攻略!德州之星扫描器,we... 必看攻略!德州之星扫描器,wepoker怎么买辅助,解密教程(有挂透视)是一款可以让一直输的玩家,快...
我来教大家!德州透视是真的假的... 此外,数据分析德州(德州透视是真的假的)辅助神器app还具备辅助透视行为开挂功能,通过对客户德州透视...
玩家攻略!pokemmo手机版... 玩家攻略!pokemmo手机版脚本免费,wepoker私人局辅助,wepoke教程(有挂攻略)1、玩...
最新研发!aa poker辅助... 最新研发!aa poker辅助包,wepoker破解是真的还是假的,AA德州教程(有挂教程)关于we...
玩家必看教程!hhpoker免... 玩家必看教程!hhpoker免费透视脚本,aa poker辅助,力荐教程(有挂方法)是一款可以让一直...
重大通报!wepoker破解游... 重大通报!wepoker破解游戏盒子,wepoker破解器,可靠技巧(有挂透视);实战中需综合运用上...
重大发现!德普之星透视辅助插件... 重大发现!德普之星透视辅助插件,wepokerplus开挂,解密教程(有挂软件);致您一封信;亲爱德...