简体   繁体   中英

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

在此处输入图片说明

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.

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>

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