AngularJs directive reports wrong height

笑着哭i 提交于 2019-12-24 20:45:50

问题


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

The directive itself is here:

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();
    }
  }
});

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?


回答1:


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

The following css should fix the problem:

map {
    display: block;
}

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'.



来源:https://stackoverflow.com/questions/14855643/angularjs-directive-reports-wrong-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!