Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 289
Edon Avatar asked Jan 30 '23 20:01

Edon


1 Answers

There were a few syntax issues

<input type="text" 
   placeholder={{placeholderText}}
   (focus)="placeholderText = ''" 
   (blur)="placeholderText = 'the placeholder'">
like image 148
Günter Zöchbauer Avatar answered Feb 03 '23 04:02

Günter Zöchbauer