在IE 11中没有得到属性值

时间:2017-05-22 16:09:44

标签: angularjs internet-explorer angularjs-directive ie11-developer-tools

我有一个自定义指令" customDir"具有一个属性" headerwidth"。以下代码在chrome,safari& Firefox浏览器。但是没有在IE中获取属性值。

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

1 个答案:

答案 0 :(得分:0)

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