简体   繁体   中英

Angular 2 focus and blur for input elements

I wrote an input field in Angular 2 that has a placeholder value.

On focus, the input field should become empty.

On blur, the input field should return to the placeholder value.

However, on blur nothing happens. Here is my input field:

<input type="text" 
       placeholder={{placeholderText}}
       onfocus="this.placeholder = ''" 
       (blur)="this.placeholder = placeholderText">

How can I change the placeholder text on blur, in Angular 2?

There were a few syntax issues

<input type="text" 
   placeholder={{placeholderText}}
   (focus)="placeholderText = ''" 
   (blur)="placeholderText = 'the placeholder'">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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