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();
}
};
})
你的控制器套'headerWidth'。你的指令定義了'headerwidth'。這些是不同的名字。 –
@MikeMcCaughan我更新了代碼..請再檢查一次。上面的代碼在Chrome瀏覽器,Safari瀏覽器和Mozilla瀏覽器工作正常iIm面臨的問題只在IE 11 –
@MikeMcCaughan你可以檢查我的答案與您的本地IE11的例子嗎?我證實它正在工作,但OP說它不工作,聽起來有線。 – Pengyy