AngularJs指令报告错误高度 [英] AngularJs directive reports wrong height

查看:105
本文介绍了AngularJs指令报告错误高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了的jsfiddle来形容我的问题。 http://jsfiddle.net/rzajac/MMud3/

I have created the jsFiddle to describe my problem. http://jsfiddle.net/rzajac/MMud3/

指令本身是在这里:

var myApp = angular.module('myApp', []);

myApp.directive('map', function(){
  return {
    restrict: 'E',
    scope: {},
    link: function(scope, elem, attrs)
    {
      elem
        .height(400)
        .width(600)
        .vectorMap({
          map: 'usa_en',
          backgroundColor: null,
          color: '#ffffff',
          hoverColor: '#999999',
          selectedColor: '#666666',
          enableZoom: false,
          showTooltip: true
        });

      document.getElementById('mapHeight').value = elem.height();
    }
  }
});

该指令是创建内部本身的HTML和SVG元素。但是,当我试图让创建地图的高度,我得到19,而不是400.我在做什么错了?

The directive is creating html and SVG elements inside itself. But when I'm trying to get the height of created map i get 19 instead of 400. What am I doing wrong?

推荐答案

这似乎有一些默认样式的<地图> 正在影响高度标记计算。

It seems that there are some default styles for the <map> tag that are affecting the height calculation.

下面的CSS应该解决这个问题:

The following css should fix the problem:

map {
    display: block;
}

要解决这个问题的另一种方法是将指令申报改变风格的属性的( A )。更改&LT;地图&GT; &LT; D​​IV地图&GT;&LT; / DIV&GT; 和指示限制:'E'限制:'A'

Another way to fix it is to change the directive declaration style to attribute (A). Change <map> to <div map></div> and on the directive restrict: 'E' to restrict: 'A'.

这篇关于AngularJs指令报告错误高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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