![](/img/trans.png)
[英]Purpose of assigning a value to the Angular template element reference?
[英]Angular 2 template's element reference not working properly
我正在嘗試使用角度參考元素直接從模板操縱html p標簽文本,但出現錯誤
這是我的代碼
<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>
我正在使用本書中的這段代碼,自己發現自己沒有任何問題。
在您的組件中聲明一個variable
在p
標簽中引用此variable
:
<p *ngIf="queuedPomodoros > 0">{{ variable }}</p>
更改variable
的值:
<pomodoro-task-icons
[task]="queuedTask"
(mouseover)="variable = queuedTask.name"
(mouseout)="variable = 'text'">
</pomodoro-task-icons>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.