Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Binding to an input text field or a text area


In this recipe, we will show you how to bind an input value from a text field or text area to a variable; so in effect, we now perform data binding from the UI to the code, and we have two-way data binding. You can find the code in the project pol_text.

How to do it...

  1. The script starts with web\index.html, where a component with the name pol-text is imported through the following line:

    <link rel="import"href="pol_text.html">

    From this, we know that the component is defined in pol_text.html, and the code behind it is in a file named pol_text.dart. For a discussion of the other tags, see the first recipe.

  2. The code for pol-text is defined in pol_text.dart:

    import'package:polymer/polymer.dart';
    
    @CustomTag('pol-text')
    classPoltext extends PolymerElement {
      @observable String comps;
      
      Poltext.created() : super.created() {  }
    }
  3. The structure of the component is outlined in pol_text.html:

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