AngularJs element.height()不是一个函数一个函数、不是、AngularJs、element

2023-09-13 02:57:27 作者:你的怜悯我不需要

我试图使该会影响元素的宽度/高度指令。翻翻例子我已经看到了你可以参考相应的功能获得/设置宽度/高度。例如,在指令链接功能我尝试做:

I am trying to make a directive that would influence element width/height. Looking through examples I've saw that you can get/set width/height by referencing appropriate function. For example in link function of directive I try to do:

    function link(scope, element, attr) {
        var height = element.height();
    }

然而,在我的code我得到错误:element.height不是一个函数

However in my code I get "Error: element.height is not a function".

我缺少参考了一些angular.js模块/库或文档不是最新的?

Am I missing reference to some angular.js module/library or documentation is not up to date?

推荐答案

如果您不包括jQuery的角度替换其自己的小图书馆,jqLit​​e。 jqLit​​e没有为DOM元素的高度()函数​​,所以你要么需要编写自己的,或在项目中使用完整版本的jQuery。

If you are not including jQuery angular substitutes its own smaller library, jqLite. jqLite does not have a height() function for DOM elements, so you will either need to write your own or use the full version of jQuery in your project.

有限jqLit​​e API是这里。

The limited jqLite api is here.