通过dart代码实例化聚合物元素
我正在尝试在Dart代码中实例化一个通过dart代码实例化聚合物元素,dart,dart-polymer,Dart,Dart Polymer,我正在尝试在Dart代码中实例化一个Polymer元素 以下是我的要点: @CustomTag('card-component')) 类CardComponent扩展了聚合关系{ @出版 弦乐演奏者姓名; CardComponent.created():super.created(); } 到目前为止,我发现工作的唯一方式是: Element y=new Element.tag('card-component'); 但我真正想做的是通过组件的访问器(而不是通过HtmlElement的属性)访
Polymer
元素
以下是我的要点:
@CustomTag('card-component'))
类CardComponent扩展了聚合关系{
@出版
弦乐演奏者姓名;
CardComponent.created():super.created();
}
到目前为止,我发现工作的唯一方式是:
Element y=new Element.tag('card-component');
但我真正想做的是通过组件的访问器(而不是通过HtmlElement
的属性)访问组件的值。有没有一种方法可以直接在Dart中实例化CardComponent
,而不使用元素.tag
方法?我尝试以多种方式使用CardComponent.created()
方法,但也不起作用
如果您想知道我为什么要这样做,那么我想将参数传递给我的构造函数,或者甚至使用工厂在理想世界中创建组件
编辑:读完后,我终于能够做我想做的事了。我只需要把这个放到我的部件上
FactoryCardComponent(String playerName)=>document.createElement(“卡组件”)
..属性={
“playerName”:playerName
};
然后像这样实例化它:
CardComponent myNewCard=新的CardComponent(“Pacane”);
我不知道您所说的“通过组件的访问器(而不是通过HtmlElement的属性)访问组件的值”的确切含义是什么
(新元素.tag('card-component')作为CardComponent)
…playerName='blabla';
通过添加自定义工厂构造函数,可以像使用普通构造函数一样使用元素
@CustomTag('card-component'))
类CardComponent扩展了聚合关系{
@出版
弦乐演奏者姓名;
CardComponent.created():super.created();
工厂卡片组件卡片组件(){
返回新元素.tag('card-component');
}
}
var cc=new CardComponent()…playerName='blabla';
如果您想从main()
而不是从另一个组件中执行此操作,请确保main()
包含聚合物(初始化代码),感谢as CardComponent
技巧!但这家工厂确实是我想要的另见