0

我有一个自定义指令“customDir”,其中一个属性为“headerwidth”。以下代码在Chrome浏览器中完美运行,safari & firefox。但没有获得IE中的属性值。IE 11中没有获取属性值

HTML

<custom-dir headerwidth="headerWidth" gfilter="__filter" pidx="$parent.$index" cidx="$index" config="gantt_config" v4data="v4.gantt_data"></custom-dir> 

JS代码

.controller("myCtrl", function($scope) { 
    $scope.headerWidth = 'test'; 
}) 
.directive('customDir', function ($compile) { 
    return { 
     restrict: 'EA', 
     scope: { 
      headerwidth: "=", 
      gfilter: "=", 
      pidx: "=", 
      cidx: "=", 
      config: "=", 
      v4data: "=" 
     }, 
     link: function (scope, element, attrs) { 

      scope.$watch('gfilter', function() { 
       renderTemplate(); 
      }, true); 

      let getX = function (y1) { 
       return scope.headerwidth * (y1 - scope.gfilter.fromYear) + (3 * (y1 - scope.gfilter.fromYear)); 
      }; 

      let getWidth = function (y1, y2) { 
       return ((scope.headerwidth * (y1 - y2)) + 84 + 34); 
      }; 

      var currentElement = element; 
      let renderTemplate = function() { 
       let rectLine = ''; 
       if (scope.v4data[scope.config.sY_field] && scope.v4data[scope.config.eY_field]) { 
        let __X = getX(scope.v4data[scope.config.sY_field]['year']); 
        let __W = getWidth(scope.v4data[scope.config.eY_field]['year'], scope.v4data[scope.config.sY_field]['year']); 

        rectLine = '<rect x="' + __X + '" y="6" width="' + __W + '" height="8" fill="#cacaca" />'; 
       } 

       let html = '<svg xmlns="http://www.w3.org/2000/svg" height="18px" width="100%">\ 
        <g id="g_'+ scope.pidx + '_' + scope.cidx + '">\ 
         '+ rectLine + '\ 
        </g>\ 
       </svg>'; 

       var replacementElement = $compile(html)(scope); 
       currentElement.replaceWith(replacementElement); 
       currentElement = replacementElement; 
      }; 

      renderTemplate(); 
     } 
    }; 
}) 
+0

你的控制器套'headerWidth'。你的指令定义了'headerwidth'。这些是不同的名字。 –

+0

@MikeMcCaughan我更新了代码..请再检查一次。上面的代码在Chrome浏览器,Safari浏览器和Mozilla浏览器工作正常iIm面临的问题只在IE 11 –

+0

@MikeMcCaughan你可以检查我的答案与您的本地IE11的例子吗?我证实它正在工作,但OP说它不工作,听起来有线。 – Pengyy

回答

0
<custom-dir headerwidth="{{headerWidth}}" gfilter="__filter" pidx="$parent.$index" cidx="$index" config="gantt_config" v4data="v4.gantt_data"></custom-dir>