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

StackOverflow https://stackoverflow.com/questions/13899000

  •  09-12-2021
  •  | 
  •  

Question

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.

Was it helpful?

Solution

@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>

OTHER TIPS

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 ':' ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top