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真假透视挂操作!有哪些免费的wpk作弊码,红龙PoKerai多功能透视挂工具1、有哪些免费的w...
细节方法辅助!聚游广东麻将ai... 很多人使用云端 AI 时,都担心聚游广东麻将、内部资料上传带来隐私风险。这款本地运行的 AI 黑科技...
WPK俱乐部辅助指引!wpk作... WPK俱乐部辅助指引!wpk作弊最怕三个东西,德扑之星ai多功能辅助app1、很好的工具软件,可以解...
查到实测辅助器!科乐四平麻将a... 您好:科乐四平麻将这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别...
WPK透视透视挂绝活儿!wep... 您好,wepoker软件辅助程序这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...
揭秘几款辅助器!大众互娱ai辅... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...
WPK模拟器辅助器积累!wep... WPK模拟器辅助器积累!wepoker究竟有没有透视,智星菠萝德州ai多功能辅助器教程1、金币登录送...
总结教程辅助器!丫丫棋牌ai辅... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成丫丫棋牌解析、 AI 处理、丫丫棋牌...
WPK私人局辅助教程书!wep... WPK私人局辅助教程书!wepoker高级辅助,wpkai多功能辅助技巧1、用户打开应用后不用登录就...
盘点几款透视挂!银河麻将ai透... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...