How to pass a constant or literal data via an attribute while instantiating dart web component?

本小妞迷上赌 提交于 2019-12-13 19:43:10

问题


Definition:

<element name="x-card" constructor="Card" extends="div">
  <template>
    <div>{{titleText}}</div>
  </template>
  <script type="application/dart">
    import 'package:web_ui/web_ui.dart';

    class Card extends WebComponent {
      String titleText = '';
    }
  </script>
</element>

Instantiation:

<x-card data-value="titleText:something"></x-card>

or

<x-card titleText="something"></x-card>

Nothing is working. Here something is not a variable. Its a string literal. How do i go about passing it? Also what if i want to instantiate array of x-cards? Say i have a dart array named cardTitleArray.


回答1:


@financeCoding, data-value is deprecated. They say use attribute=value instead of data-value="attribute:value".

Never mind, my problem is solved. The following works.

<x-card title-text="{{'Aint it supercool'}}"></x-card>



回答2:


Looking at the code that does make reference to 'data-value'

http://www.dartlang.org/articles/dart-web-components/#component-instantiation

https://github.com/dart-lang/web-ui/blob/master/example/explainer/countcomponent.html

It does not seem like the actual code uses it. Could you use the other way or now or post the code online? Maybe a space is needed after ':' ?



来源:https://stackoverflow.com/questions/13899000/how-to-pass-a-constant-or-literal-data-via-an-attribute-while-instantiating-dart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!