检测元件的outerHeight()与NG-重复 [英] Detect outerHeight() of element with ng-repeat

查看:136
本文介绍了检测元件的outerHeight()与NG-重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测将取决于从一个数据库中的数据改变元素的高度。

I'm trying to detect the height of an element that will change depending on data from a database.

我用.outerHeight成功之前,却无法做到这一点,它包含从纳克重复数据的元素。

I have used .outerHeight successfully before but can't do this on an element that contains data from a ng-repeat.

有没有办法做到这一点,一旦数据填充角元素还是有检测这个另一种方法?

Is there a way to do this once the data has populated the angular element or is there another method of detecting this?

推荐答案

是的,你需要创建一个属性指令,并把它放在NG重复。

Yes, you need to create an attribute directive and put it on the ng-repeat.

<div ng-repeat="whatever in items" outer-height></div>

该指令将它编译之后发生的链接功能。

The directive will have a link function which happens after it has compiled.

app.directive('outerHeight', function(){
  return{
    restrict:'A',
    link: function(scope, element){
       //using outerHeight() assumes you have jQuery
       //use Asok's method in comments if not using jQuery
       console.log(element.outerHeight()); 
    }
  };
});

下面是一个Plnkr将记录outerHeight安慰:的http:// plnkr。 CO /编辑/ AdGpnzJilW2179Ybuurk?p = preVIEW

Here's a Plnkr which will log the outerHeight to console: http://plnkr.co/edit/AdGpnzJilW2179Ybuurk?p=preview

注意您将需要使用 $观看,并得到一个新的高度,如果数据发生变化。

Note You will need to use a $watch and get a new height if data changes.

这篇关于检测元件的outerHeight()与NG-重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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