我想在 Angular 2 NGX Datatable 中将日期列格式化为短日期。
这是HTML:
<ngx-datatable
[rows]="toDos"
[columns]="columns">
</ngx-datatable>
这是组件 TypeScript
import { Component, OnInit } from '@angular/core';
import { IToDo } from '../shared/todo';
import { ToDoService } from '../shared/todo.service';
@Component({
selector: 'app-todo-list',
templateUrl: './todo-list.component.html',
styleUrls: ['./todo-list.component.css']
})
export class TodoListComponent implements OnInit {
toDos: IToDo[];
columns = [
{ prop: 'toDoId' },
{ name: 'To Do', prop: 'name' },
{ prop: 'priority' },
{ prop: 'dueDate' },
{ prop: 'completed' }
];
constructor(private _toDoService: ToDoService) {
}
ngOnInit() {
this.toDos = this._toDoService.getToDos();
}
}
我在 HTML 中试过这个,但它给出了一个模板解析错误:
<ngx-datatable
[rows]="toDos"
[columns]="columns"
<ngx-datatable-column prop="dueDate">
<ng-template let-value="value" ngx-datatable-cell-template>
{{value | date[:shortDate]}}
</ng-template>
</ngx-datatable-column>
>
</ngx-datatable>