在对AngularJS NG-src的图像加载事件 [英] Image loaded event in for ng-src in AngularJS

查看:123
本文介绍了在对AngularJS NG-src的图像加载事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有图像看起来像< IMG NG-SRC =动态插入网址/> 。当单个图像加载,我需要申请iScroll刷新()方法,以便使图像滚动。

I have images looking like <img ng-src="dynamically inserted url"/>. When a single image is loaded, I need to apply iScroll refresh() method so that to make image scrollable.

什么是要知道当图像满载运行一些回调的最佳方式?

What is the best way to know when an image is fully loaded to run some callback?

推荐答案

下面是一个例子如何调用图像的onload 的http://的jsfiddle .NET / 2CsfZ / 2 /

Here is an example how to call image onload http://jsfiddle.net/2CsfZ/2/

基本的想法是创建一个指令,并作为属性添加到img标签中。

Basic idea is create a directive and add it as attribute to img tag.

JS:

app.directive('imageonload', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
            element.bind('load', function() {
                alert('image is loaded');
            });
            element.bind('error', function(){
                alert('image could not be loaded');
            });
        }
    };
});

HTML

 <img ng-src="{{src}}" imageonload />

这篇关于在对AngularJS NG-src的图像加载事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆