绑定到 Dart 中的 <time>.datetime 属性

Binding to <time>.datetime attribute in Dart

我想创建一个组件,其中有一个 <time/> 标签。我正在尝试绑定到它的 datetime 属性。示例:

// component:

String isoFormat;

<!-- html template: -->

<time datetime="{{isoFormat}}">{{display}}</time>

但是,我遇到了这个编译时错误:

ParseErrorLevel.FATAL: Can't bind to 'datetime' since it isn't a known native property or known directive. Please fix typo or add to directives list.

有什么解决办法吗?或者我应该放弃它?提前致谢。

由于 datetime 是原生 HTML5 属性,您是否尝试在其前面加上 attr. 前缀?

例如:

<time [attr.datetime]="isoFormat">{{display}}</time>

看这里:https://webdev.dartlang.org/angular/guide/template-syntax#other-bindings

要么按照 Crazywater 的建议进行操作,要么使用 dateTime 而不是 datetime

<time dateTime="{{isoFormat}}">{{display}}</time>

另见 https://developer.mozilla.org/en-US/docs/Web/API/HTMLTimeElement

StackBlitz example (in app/app.component.html) 它是 TypeScript 但对于这个例子来说并不重要。