Instantiating polymer element via dart code

后端 未结 1 579
离开以前
离开以前 2020-12-11 23:25

I\'m trying to instantiate a Polymer element in my Dart code.

Here\'s my element:

@CustomTag(         


        
1条回答
  •  萌比男神i
    2020-12-11 23:46

    I don't know what exactly you mean by "to access the values of my component by their accessors (instead of by attributes of HtmlElement)"

    (new Element.tag('card-component') as CardComponent)
        ..playerName = 'blabla';
    

    adding a custom factory constructor allows you to use the element as if it had a normal constructor

    @CustomTag('card-component')
    class CardComponent extends PolymerElement {
      @published
      String playerName;
    
      CardComponent.created() : super.created();
    
      factory CardComponent CardComponent() {
        return new Element.tag('card-component');
      }
    }
    
    var cc = new CardComponent()..playerName = 'blabla';
    

    If you want to do this from main() not from within another component, ensure that main() contains the Polymer (initialization code why am I getting type error on polymer.dart element?, how to implement a main function in polymer apps)

    0 讨论(0)
提交回复
热议问题