Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过dart代码实例化聚合物元素_Dart_Dart Polymer - Fatal编程技术网

通过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的属性)访

我正在尝试在Dart代码中实例化一个
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
技巧!但这家工厂确实是我想要的另见