首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angularjs只在加载其子女中的图像时才显示指令。

Angularjs只在加载其子女中的图像时才显示指令。
EN

Stack Overflow用户
提问于 2015-01-09 12:38:12
回答 2查看 342关注 0票数 1

我有一个包含图像元素的列表。我想显示的元素,只有当那里的图像已经完全加载。

到目前为止,我的情况如下:

代码语言:javascript
复制
 .directive...
   template: '<md-item ng-show="{{showItem}}" ng-transclude></md-item>',
   link: function($scope, iElm, iAttrs, controller) {
     $scope.showItem = false;
     iElm.find('img').bind('load' , function(e) {
       $scope.$apply('showItem = true');
     });
   }

在DOM中有一个关于2-3个子级的图像,绑定函数工作得很好,但是'$scope.$apply('showItem = true');‘部件什么都不做.

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-09 12:44:00

对于ng显示,不需要插值。你可以试试这个

代码语言:javascript
复制
.directive...
   template: '<md-item ng-show="showItem" ng-transclude></md-item>',
   link: function($scope, iElm, iAttrs, controller) {
     $scope.showItem = false;
     iElm.find('img').bind('load' , function(e) {
       $scope.$apply('showItem = true');
     });
   }
票数 3
EN

Stack Overflow用户

发布于 2015-01-09 12:41:48

就这么做吧:

代码语言:javascript
复制
.directive...
 template: '<md-item ng-show="showItem" ng-transclude></md-item>',
 link: function(scope, iElm, iAttrs, controller) {
   scope.showItem = false;
   iElm.find('img').bind('load' , function(e) {
     scope.showItem = true;
   });
 }

在链接函数中,建议您使用“作用域”而不是$scope。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27860772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档