简体   繁体   English

事件onclick动态

[英]Event onclick dynamic

i use https://angular.io/guide/dynamic-form angular dynamic form. 我使用https://angular.io/guide/dynamic-form角度动态形式。 How is it possible to intercept the click event on every input field of the web page? 如何拦截网页的每个输入字段上的click事件? I tried 我试过了

<pre>
<df-question [question]="question" [form]="form" ng-
click="onContainerClick($event);"></df-question>
</pre>

Thank you 谢谢

Instead of applying the click to the tag, just in your DynamicFormQuestionComponent ( df-question ) add click event on the input field (code taken from the docs) 只需在您的DynamicFormQuestionComponentdf-question )中将click事件添加到输入字段(取自docs的代码),而不是对标签应用click

HTML: HTML:

<input (click)="onContainerClick($event)" *ngSwitchCase="'textbox'" 
       [formControlName]="question.key"
       [id]="question.key" [type]="question.type">

BTW, you were using ng-click which is not Angular, but AngularJS. 顺便说一句,您使用的不是Angular,而是AngularJS的ng-click

TS: TS:

onContainerClick(event) {
  console.log('clicked')
}

DEMO (check console) https://plnkr.co/edit/MbwuhWJrJOwuW23ZbzsC?p=preview 演示 (检查控制台) https://plnkr.co/edit/MbwuhWJrJOwuW23ZbzsC?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM