Aren Hovsepyan Aren Hovsepyan - 4 months ago 24
AngularJS Question

Angular 2 template's element reference not working properly

I am trying to manipulate html p tags text directly from template using angulars reference elements, but getting error

enter image description here

this is my code

<p>
<span *ngFor="let queuedTask of tasks">
<pomodoro-task-icons
[task]="queuedTask"
(mouseover)="tooltip.innerText = queuedTask.name"
(mouseout)="tooltip.innerText = 'text'">
</pomodoro-task-icons>
</span>
</p>
<p *ngIf="queuedPomodoros > 0" #tooltip>{{tooltip.innerText || 'Mouseover for details' }}</p>


I am using this code from book and don't find any problem in realization myself.

Answer

Declare a variable in your component

Reference this variable in the p tag:

 <p *ngIf="queuedPomodoros > 0">{{ variable }}</p>

Change the value of the variable:

  <pomodoro-task-icons
    [task]="queuedTask"
    (mouseover)="variable = queuedTask.name"
    (mouseout)="variable = 'text'">
  </pomodoro-task-icons>