如何解决如何完成我的正式时间组件以获取价值并进行输出
我正在尝试基于 formly 创建一个 ngx material timepicker 时间组件。
我的问题是如何绑定用户值并将此值作为时间戳输出,如 @input()
。
我对网上找到的几个例子感到非常困惑。
这是我的代码:
formly-time.component.ts
import {Component,Input,OnInit} from '@angular/core';
import {FieldType} from '@ngx-formly/material';
import {UserService} from '../../../common/services/user.service';
import {formatDate} from '@angular/common';
import {FormControl} from '@angular/forms';
@Component({
selector: 'ui-formly-time',templateUrl: './formly-time.component.html',styleUrls: ['./formly-time.component.scss']
})
export class FormlyTimeComponent extends FieldType implements OnInit{
@input() timestamp: number;
value: string;
itemControl = new FormControl();
constructor( public currentUser: UserService ) {
super();
this.timestamp = 1589175000000; //hardcoded for the moment
}
ngOnInit() {
super.ngOnInit();
console.dir( this.currentUser.data.getValue().preferences.locale );
this.value = formatDate( this.timestamp,'HH:mm',this.currentUser.data.getValue().preferences.locale );
this.itemControl.setValue( this.value );
}
}
formly-time.component.html
<ngx-timepicker-field [format]="24" [defaultTime]="value" [formControl]="itemControl"></ngx-timepicker-field>
有人可以帮助我吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。