Search code examples
dartdart-polymer

Dart Language: Polymer - Working with views


I'm developing my first "complex" application on Dart and I'm finding some trouble on how to work with more than one view (I want to develop the application to run within a single page).

First of all, I'm assuming that this (using Polymer) is the right approach to work with various views (or "app screens") of the application. However, if it's not, I would like to know (of course). And by "app screens", I'm saying something like creating various forms in Java.

So, for instance, I have two buttons at the top of the page. When you click the first one, it shows a view with an user registration area. When you click the second button, it shows a view with an editable grid.

Could you give me some code example of this simple app?


Solution

  • You could use the template if functionality.
    This way views that are currently not active are automatically removed from the DOM and automatically inserted again when the model attribut changes.

    <polymer-element name='app-element'>
      <template>
        <template if='{{appModel.view == 'view1'}}'>
          <view1></view1>
        </template>
    
        <template if='{{appModel.view == 'view2'}}'>
          <view2></view2>
        </template>
      </template>
      <script ...>
    </polymer-element>