最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ion-input onclick in ionic 4 angular 6 - Stack Overflow

programmeradmin5浏览0评论

I have a view with a ion-input inside a form:

      <form class="inputs-in-block" [formGroup]="userForm">
        <ion-input type="text" placeholder="Username" (click)='onClickFuntion($event)'></ion-input>
      </form>

I want to catch the onClick event after it is fired, but I do not manage to achieve it because after clicking on the input, the onClickFunction($event) is not called. This is the definition of the function:

onClickFunction(event) {
  console.log('Event caught');
} 

I have tried without the event and it is not working either.

Is the click event available for s in the latest version? Any idea to solve it?

I have a view with a ion-input inside a form:

      <form class="inputs-in-block" [formGroup]="userForm">
        <ion-input type="text" placeholder="Username" (click)='onClickFuntion($event)'></ion-input>
      </form>

I want to catch the onClick event after it is fired, but I do not manage to achieve it because after clicking on the input, the onClickFunction($event) is not called. This is the definition of the function:

onClickFunction(event) {
  console.log('Event caught');
} 

I have tried without the event and it is not working either.

Is the click event available for s in the latest version? Any idea to solve it?

Share Improve this question edited Sep 4, 2018 at 13:14 lsantamaria asked Sep 4, 2018 at 13:04 lsantamarialsantamaria 1781 gold badge2 silver badges12 bronze badges 2
  • Are you testing the click on a device or in your browser? – fransyozef Commented Sep 4, 2018 at 14:07
  • Yes, in my browser – lsantamaria Commented Sep 4, 2018 at 14:08
Add a ment  | 

3 Answers 3

Reset to default 2

I think it's a typo:

You have in your template:

(click)='onClickFuntion($event)'

But in your ts file :

onClickFunction(event) {
  console.log('Event caught');
} 

onClickFuntion <-> onClickFunction ... see the "c"

You'll have to send it as well from the template. That's missing from your template. (click)='onClickFuntion($event)

<ion-input 
  type="text" 
  placeholder="Username" 
  (click)='onClickFuntion($event)'>
</ion-input>

I think, you should use ionClick to trigger click event.

You'r code should work if you do below changes

<form class="inputs-in-block" [formGroup]="userForm">
        <ion-input type="text" placeholder="Username" (ionClick)='onClickFuntion($event)'></ion-input>
      </form>
发布评论

评论列表(0)

  1. 暂无评论