I have to show the input characters counter several times in distinct components. So I thought it was best to create a component for it.
Example:
I have tried to make a template reference variable and show its value. However, the count isn't dynamic. It stays static. Here's the live example in StackBlitz.
The code is very simple:
app.component.html
<input type="text" #input>
<app-caracter-counter [input]="input.value.length"></app-caracter-counter>
And the code of the component I created:
caracter-count.component.ts
export class CaracterCounterComponent implements OnInit {
@Input() input:number;
}
This was the simplest way I found, but doesn't work.
I tried binding an event emmitter, but that would require to use the @Output in all components that I use this caracter-counter
.
Is there any way to make this component works using only template tags (in the component that I'll be using the caracter-counter
)?