Pass parameters to Dart Polymer element

前端 未结 3 1636
余生分开走
余生分开走 2021-01-06 00:05

The only solid example I could find for Dart Polymer doesn\'t use any parameters. How can I pass parameters to the template. Is it done through the constructor?

My s

3条回答
  •  既然无缘
    2021-01-06 00:31

    even though this is a bit old: You actually can pass parameters like this:

    
    

    And your custom element should look something like:

    @CustomTag('my-custom-element')
    class MyCustomElement extends PolymerElement {
      ...
      @published bool booleanAttr;
      @published String valueAttr;
      ...
    }
    

    -- EDIT --

    But as already pointed out this can be easily done for polymerelements with a factory:

    import 'package:polymer/polymer.dart';
    import 'dart:html';
    
    @CustomTag('my-custom-element')
    class MyCustomElement extends PolymerElement {
      String a;
    
      factory MyCustomElement.custom(String _a) {
        MyCustomElemente = new Element.tag('my-custom-element');
        e..a = _a
        // ...
        ..initialized();
        return e;
      }
    
      MyCustomElement.created() : super.created() {
    
      }
    
      void initialized() {
        print("initialized: " + a);
      }
    }
    

提交回复
热议问题