簡體   English   中英

角度2:當元素出現在屏幕上時執行功能

[英]Angular 2: execute a function when the element appears on the screen

使用Angular 2,當元素出現在屏幕上時如何執行功能? 具有良好的性能。

上下文如下:我有一個循環,當元素出現在屏幕上時,我想從控制器執行功能。

<ion-list>
    <button ion-item *ngFor="#item of items" (click)="itemTapped($event, item)">
      <ion-icon name="{{item.icon}}" item-left></ion-icon>
      {{item.title}}
      <div class="item-note" item-right>
        {{item.note}}
      </div>
      <img [src]="item.imageSrc">
    </button>
  </ion-list>

在Angular 1中,我使用了ng-init和函數“ article.getImg()”以及其他上下文(不立即顯示所有圖像)

<img ng-show="article.hasImage" ng-init="article.imageLookedFor == false ? article.getImg() : null" ng-src="{{article.imageSrc}}" imageonloadheadline />

<img>元素具有一個load事件,您可以收聽:

<img [src]="item.imageSrc" (load)="doSomething()">

另請參閱在加載新圖像時刪除圖像?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM