问题描述
我正在尝试基于 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 (将#修改为@)