获取里面AnguarJS指令元素的父高度 [英] Get element parent height inside directive in AnguarJS

查看:226
本文介绍了获取里面AnguarJS指令元素的父高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何从一个元素从内部指令集父高度?

这是我现在,很明显它不工作。

  VAR VALIGN = angular.module(VALIGN,[])
.directive('VALIGN',函数(){
  返回{
        限制:AC,
        链接:功能(范围,E){            e.parent.height(1200);
            的console.log(e.parent.height);
        }
    };
});


解决方案

您可以使用高度方法jqLit​​e / jQuery的的:

 链接:功能(范围,E){
    。e.parent()高度(1200);
    (e.parent()高度())的console.log;
}

或者你可以用 parentNode 属性,这是父元素的引用做纯的JavaScript:

 链接:功能(范围,E){
    E [0] .parentNode.style.height = 1200 +'像素';
}

还要注意,因为电子是这里的jqLit​​e / jQuery的实例,它是一个单一的元素的类似数组的集合,你需要使用 [0] 来访问HTML元素的原始

How do you get and set the parent height from an element from inside a directive?

This is what I have now, obviously it's not working.

var vAlign = angular.module("vAlign", [])
.directive('vAlign', function() {
  return {
        restrict : "AC",
        link: function(scope, e){

            e.parent.height(1200);
            console.log(e.parent.height);
        }
    };
});

解决方案

You can use parent and height methods of jqLite/jQuery:

link: function(scope, e) {
    e.parent().height(1200);
    console.log(e.parent().height());
}

Or you could do it in pure javascript with parentNode property, which is a reference to parent element:

link: function(scope, e) {
    e[0].parentNode.style.height = 1200 + 'px';
}

Also note, that since e is an jqLite/jQuery instance here which is a array-like collection of one single element, you need to use [0] to access raw HTMLElement.

这篇关于获取里面AnguarJS指令元素的父高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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