passing parameter/input data to custom elements in DART

后端 未结 3 888
天命终不由人
天命终不由人 2021-01-24 16:28

I created a custom element, and want to send data / parameters to it:

my element code is:

   class SaveBtn         


        
3条回答
  •  情话喂你
    2021-01-24 16:53

    This is another solution that worked with me before reading the posted answers, I liked @Gunter answer and will adapt it.

    class SaveBtn extends HtmlElement  {
      static final tag = 'save-button';
      factory SaveBtn()=>new Element.tag(tag);
    
      var shadow, btn;
    
      SaveBtn.created() : super.created() {
        shadow = this.createShadowRoot();
    
        btn = new ButtonElement()
            ..text="save"
            ..style.height= '20px'  
            ..style.borderBottom='1px solid #D1DBE9'; 
    
        btn.text = this.getAttribute('data-name');
    
        shadow.nodes..add(label)..add(btn);
      } 
    
      Element launchElement(name){ 
        btn.text= name;
        return (shadow); 
      }
    }
    

    and called the element as:

    var btn=new SaveBtn()..launchElement('click me');
    

提交回复
热议问题