简体   繁体   中英

Can I add Dart Web UI bindings to DOM elements created in code?

In the Dart Web UI package, it is possible to create bindings using the {{}} or bind-value syntax. Is this also possible, when DOM elements are created in code?

Something like

new Element.html('<div>Value: {{str}}</div>');

and

new Element.html('<input type="text" bind-value="str">');

binding an event to str , without manually piecing the strings together?


Note : this question was asked earlier today, but was deleted before it was answered, but I wanted to know the answer, so I'm reposting it.

Quick answer, no.

The bindings need to be processed by the dwc transformer, which converts Web Components and MDV code into "vanilla" Dart and HTML (suitable for compilation to "vanilla" JavaScript).

Generally, you should use <template> tags to instantiate new elements.

An alternative is to wrap these bits of text inside a custom element, which you can transform with dwc and instantiate manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM