Seeming to set a 1-directional databind even though it should be bidirectional


Been working with 2 files: with the data as follows:


library webserver_ajax.lib.iron_ajax;

import 'package:web_components/web_components.dart';
import 'package:polymer/polymer.dart';
import 'package:polymer_elements/iron_ajax.dart';
import 'package:polymer_elements/iron_request.dart';

///Uses [IronAjax]
class IronAjaxSample extends PolymerElement {

  String f_name;

  String l_name;

  int identification;

  //IronAjax ia = querySelector('myAjaxId');

  IronAjaxSample.created() : super.created(){

  void handleResponse ( [CustomEventWrapper cew, IronRequest ir] ){
    print("handle response fired");
    var data = ir.response;
    f_name = data["f_name"];
    l_name = data["l_name"];
    identification = data["id"];

    print("$f_name $l_name: $identification");


<dom-module id="my-ajax-fetcher">

        <iron-ajax id="myAjaxId" auto
          on-response="handleResponse" ></iron-ajax>

        <div>First Name: {{f_name}}</div>
        <div>Last Name:  {{l_name}}</div>
        <div>Student ID:  {{identification}}</div>

And when the ajax call finishes it will call handleResponse which will set f_name, l_name, identification variables. The issue is that i see the variables are set in the last line of handleResponse.

It doesn’t set the markup according to say: First Name: Frank at all, it is just empty. I have determined that for some reason, handleResponse is a different scope than the other functions. How do i fix this?


In Dart you always need to use set(...) or any other method provided by Polymer to update data.

set('f_name', data["f_name"]);
set('l_name', data["l_name"]);
set('identification', data["id"]);   

In JavaScript this is not necessary for fields of a Polymer element, only for properties of complex types (custom classes, collections, …)

See also

Answered By – Günter Zöchbauer

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *