我正在尝试使用MomentJS格式化一些日期.在我尝试添加AM/PM或am/pm之前我没有问题.我有以下函数,并从Breeze EntityQuery的结果传递时间,其中时间是System.DateTime,如下所示:
function datetimeCellRendererFunc(value) {
// value = Mon Jun 15 2015 09:00:00 GMT-0500 (Central Daylight Time);
return moment(value).format("MM/DD/YYYY h:mm A");
}
Run Code Online (Sandbox Code Playgroud)
无论我在格式化中使用A还是a,我仍然会得到以下结果:
2015年6月15日上午9:00
我还需要添加其他东西吗?先感谢您!!
我正在与Formly合作并创建了几个自定义模板。组件中包含的唯一代码是对通用错误处理服务的调用,因此除了可以创建组件之外,实际上几乎没有什么需要测试的。我仅使用 Jest 进行单元测试,但无法弄清楚需要包含哪些内容才能成功编译组件。
我收到的错误是:TypeError:无法读取未定义的属性“formControl”。我不确定我的测试中缺少什么。
对于最简单的组件(主要是样式和指令 - 现在已删除),我有以下内容:
成分:
@Component({
selector: 'my-formly-field-input',
templateUrl: './formly-field-input.component.html',
styleUrls: ['./formly-field-input.component.scss']
})
export class FormlyFieldInputComponent extends FieldType {
constructor(private formErrorService: FormErrorHandlerService) {
super();
}
getError(formItem: FormControl | FormGroup | FormArray): string {
return this.formErrorService.getFormError(formItem);
}
}
Run Code Online (Sandbox Code Playgroud)
看法:
<mat-form-field [floatLabel]="'always'"
class="w-100"
[appearance]="'fill'">
<mat-label>{{field.templateOptions.label}}</mat-label>
<input matInput
[formControl]="formControl"
[type]="field.templateOptions.type || 'text'"
[step]="field.templateOptions.step || 1"
[max]="field.templateOptions.max || undefined"/>
<mat-error *ngIf="formControl.errors">
{{getError(formControl)}}
</mat-error>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
单元测试:
describe('FormlyFieldInputComponent', () => {
let component: FormlyFieldInputComponent;
let fixture: ComponentFixture<FormlyFieldInputComponent>;
const formHelperServiceStub: Partial<FormErrorHandlerService> = …Run Code Online (Sandbox Code Playgroud)