Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer core-selector does not refresh

The Dart code for my Polymer element looks like this:

@CustomTag('my-element')
class MyElement extends PolymerElement {
  final List<String> colors = toObservable(['red', 'green', 'blue']);
  MyElement.created() : super.created();
}

And the HTML looks like this:

<polymer-element name="my-element">
  <template>
    <style>
      .core-selected {
        font-weight: bold;
      }
    </style>
    <core-selector id="selector" selected="1">
      <template repeat="{{color in colors}}">
        <div value="{{color}}">{{color}}</div>
      </template>
    </core-selector>
    <hr>
    <!-- Prints the selected index, but does not update -->
    <div>{{$['selector'].selected]}}</div> 
  </template>
  <script type="application/dart" src="my_element.dart"></script>
</polymer-element>

Using <div>{{$['selector'].selected]}}</div> correctly shows the index of the selected color, but picking a different color does not refresh the value of selected. Am I using this correctly? Or is this a bug?

like image 838
Shailen Tuli Avatar asked Mar 28 '26 18:03

Shailen Tuli


1 Answers

I agree it's a bug, but in the meantime you can work around it like this

<core-selector id="selector" selected="{{selected}}">
...
<div>{{selected}}</div>

with the backing code containing the obvious

@observable int selected = 1;

I do wonder if your version works when used in a pure JS environment? But that's another question.

like image 176
James Hurford Avatar answered Apr 02 '26 18:04

James Hurford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!