PrimeNG是一个开源的UI组件库,提供了丰富的UI组件和主题,用于构建现代化的Web应用程序。在PrimeNG中,时间选择器组件用于选择时间。
要在PrimeNG的时间选择器组件中设置值,可以通过以下步骤进行操作:
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { PrimeNGConfig } from 'primeng/api';
export class YourComponent implements OnInit {
timeControl: FormControl;
constructor(private primengConfig: PrimeNGConfig) {}
ngOnInit() {
this.timeControl = new FormControl();
}
}
<p-calendar [(ngModel)]="timeControl"></p-calendar>
ngOnInit() {
this.timeControl.setValue(new Date()); // 设置为当前时间
}
通过以上步骤,你可以在PrimeNG的时间选择器组件中设置初始值。当用户选择不同的时间时,FormControl对象的值也会相应地更新。
领取专属 10元无门槛券
手把手带您无忧上云