Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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/1/typescript/9.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
如何在Angular2中获得事件绑定属性,比如(单击)或(键控),并将它们插入新的html元素中_Angular_Typescript_Polymer_Web Component - Fatal编程技术网

如何在Angular2中获得事件绑定属性,比如(单击)或(键控),并将它们插入新的html元素中

如何在Angular2中获得事件绑定属性,比如(单击)或(键控),并将它们插入新的html元素中,angular,typescript,polymer,web-component,Angular,Typescript,Polymer,Web Component,我的定制聚合物网络组件与Angular2发生故障。我不得不将它们包装在自定义指令中(这会延迟web组件的呈现,直到通过角度将它们插入DOM中) 包装的工作原理如下: <my-custom-wrapper component="custom-fancy-element"></my-custom-wrapper> ngOnInit() { var parentNode = Polymer.dom(this.element.nativeElement).parentNod

我的定制聚合物网络组件与Angular2发生故障。我不得不将它们包装在自定义指令中(这会延迟web组件的呈现,直到通过角度将它们插入DOM中)

包装的工作原理如下:

<my-custom-wrapper component="custom-fancy-element"></my-custom-wrapper>
ngOnInit() {
  var parentNode = Polymer.dom(this.element.nativeElement).parentNode;
  if (parentNode) {
    Polymer.dom(parentNode).insertBefore(this.webcomponent, this.element.nativeElement);
  }
}
这就是我想要的结果:

<custom-fancy-element (click)="someFunction()"></custom-fancy-element>
}

随后,我在指令之前插入HTML元素,如下所示:

<my-custom-wrapper component="custom-fancy-element"></my-custom-wrapper>
ngOnInit() {
  var parentNode = Polymer.dom(this.element.nativeElement).parentNode;
  if (parentNode) {
    Polymer.dom(parentNode).insertBefore(this.webcomponent, this.element.nativeElement);
  }
}
我想,在Angular 1中获取和设置属性是可能的

.directive('someDirective', function() {
   return {
     ...
     link: function (scope, element, attributes) {
       //assign attribute to web component
     }
}

但是如何在Angular2和TypeScript中执行此操作?

不支持此操作。不能将
(单击)
(keyup)
动态添加到DOM中。您可以获得一个元素并使用
addEventListener(…)


Angular2绑定语法仅在静态添加到组件模板时有效。

问题是,如何检查
指令是否具有类似
(单击)=“someFunction()”
的事件绑定属性,以便我可以将事件侦听器添加到相应的webcomponent?抱歉,我不太理解这个问题
(单击)=“someFunction()”
是一些声明性绑定,在Angular编译模板(脱机模板编译器或在创建组件时的运行时)时被删除,并替换为
addEventListener('click',…)
。当组件存在于DOM中时,任何
(单击)=“…”
都将不再存在。我真的不想在一些html标记之间检查
(单击)=“someFunction()”
的“物理”存在。我想检查是否有附加到它的事件,如(单击)或(键控)。有可能吗?我想为什么不把它作为组件的一部分添加,而是用一个条件隐藏呢<代码>