Using a list with Polymer.dart

Michael Peterson

I have a Polymer element using Dart. This element contains a simple list of numbers that are displayed in their own div tags. There is a counter at the top of the element to display how many elements are in this list.

Initially, the element is displayed correctly, but I've placed a button at the top of the element that should add an item to the list, and update the counter. The counter is updated, and items are added to the list (as the print shows), but the DOM is not updated.

Am I expecting something that shouldn't happen or am I doing something wrong here?

<link rel="import" href="packages/polymer/polymer.html">

<polymer-element name="list-test">
  <template>


    <button on-click="{{click}}">Click</button>
    <div>Counter: {{count}}</div>

    <template repeat="{{num in nums}}">
      <div>{{num}}</div>
    </template>


  </template>
  <script type="application/dart">
    import "dart:async";
    import "package:polymer/polymer.dart";

    @CustomTag("list-test")
    class listTest extends PolymerElement {

      listTest.created() : super.created();

      @observable List nums;
      @observable int count;

      void attached() {
        nums = [0];
        count = nums.length;
      }

      void click() {
        nums.add(count++);
        print(nums);
      }
    }
  </script>
</polymer-element>
Günter Zöchbauer

You need to change this line

nums = [0];

to

nums = toObservable([0]); 

or better add it to the field initializer

@observable List nums = toObservable([0]);

Otherwise only the assignment of another list to nums is recognized but not the changes inside the list.

Your attached method is missing the super call

  void attached() {
    super.attached(); // <== added
    nums = toObservable([0]); // <== can be moved to the field initializer
    count = nums.length;
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using polymer's `.job` in polymer.dart

From Dev

Using Polymer in a Dart Chrome App

From Dev

Using Polymer core elements in Dart

From Dev

Using Polymer UI Elements in Dart

From Dev

Databinding using Polymer-Dart and Dart objects

From Dev

Polymer Core-List Demo To Dart Code

From Dev

Is it possible to render a List<Element> in Polymer.dart?

From Dev

Dart/Polymer binding object attributes of a list

From Dev

Using external stylesheets in dart's polymer with polymer 0.9.5

From Dev

Using less in a polymer-dart application

From Dev

Could not find asset using Polymer.Dart

From Dev

Could not find asset using Polymer.Dart

From Dev

Template repeat not working for nested list (Polymer.dart)

From Dev

Dart Polymer error 'List' is not a subtype of type 'ObservableList' of 'value'

From Dev

Template repeat not working for nested list (Polymer.dart)

From Dev

How to get model for element in iron-list (polymer dart)?

From Dev

Polymer-Dart iron-list not binding to selected-item

From Dev

Run Polymer Dart from Cordova using pub serve

From Dev

Dynamically update a stylesheet using dart within a template in a polymer-element

From Dev

Dynamically update a stylesheet using dart within a template in a polymer-element

From Dev

How can you detect if Polymer is using Shady or Shadow DOM in Polymer Dart 1.0.0?

From Dev

Error using core-scaffold from polymer JS in the latest Polymer Dart release

From Dev

How can you detect if Polymer is using Shady or Shadow DOM in Polymer Dart 1.0.0?

From Dev

In Polymer Dart, how to build a CSS table using 1 polymer-element for the table and another for the rows and cells

From Dev

Post a list and iterate it using Dart

From Dev

Polymer Dart @initMethod not executing

From Dev

removing polymer elements in dart

From Dev

Dart Polymer application as component?

From Dev

Dart/Polymer loading screen?

Related Related

  1. 1

    Using polymer's `.job` in polymer.dart

  2. 2

    Using Polymer in a Dart Chrome App

  3. 3

    Using Polymer core elements in Dart

  4. 4

    Using Polymer UI Elements in Dart

  5. 5

    Databinding using Polymer-Dart and Dart objects

  6. 6

    Polymer Core-List Demo To Dart Code

  7. 7

    Is it possible to render a List<Element> in Polymer.dart?

  8. 8

    Dart/Polymer binding object attributes of a list

  9. 9

    Using external stylesheets in dart's polymer with polymer 0.9.5

  10. 10

    Using less in a polymer-dart application

  11. 11

    Could not find asset using Polymer.Dart

  12. 12

    Could not find asset using Polymer.Dart

  13. 13

    Template repeat not working for nested list (Polymer.dart)

  14. 14

    Dart Polymer error 'List' is not a subtype of type 'ObservableList' of 'value'

  15. 15

    Template repeat not working for nested list (Polymer.dart)

  16. 16

    How to get model for element in iron-list (polymer dart)?

  17. 17

    Polymer-Dart iron-list not binding to selected-item

  18. 18

    Run Polymer Dart from Cordova using pub serve

  19. 19

    Dynamically update a stylesheet using dart within a template in a polymer-element

  20. 20

    Dynamically update a stylesheet using dart within a template in a polymer-element

  21. 21

    How can you detect if Polymer is using Shady or Shadow DOM in Polymer Dart 1.0.0?

  22. 22

    Error using core-scaffold from polymer JS in the latest Polymer Dart release

  23. 23

    How can you detect if Polymer is using Shady or Shadow DOM in Polymer Dart 1.0.0?

  24. 24

    In Polymer Dart, how to build a CSS table using 1 polymer-element for the table and another for the rows and cells

  25. 25

    Post a list and iterate it using Dart

  26. 26

    Polymer Dart @initMethod not executing

  27. 27

    removing polymer elements in dart

  28. 28

    Dart Polymer application as component?

  29. 29

    Dart/Polymer loading screen?

HotTag

Archive