internet-explorer - AngularJs 指令的模板未在 IE9 中更新

标签 internet-explorer angularjs angularjs-directive angularjs-scope

我正在创建 AngularJS 的指令。在 Internet Explorer (IE9) 中,它无法按预期工作。它确实用模板替换了原始 html,但不更新模板的内插字符串。

它在 Chrome、Firefox 和 Safari 中正常工作

这是代码

angular.module('app', []);
angular.module('app').directive('mydirective', function () {
    return {
        replace: true,
        scope: {
            height: '@',
            width: '@'
        },
        template: '<div style="width:{{width}}px;height:{{height}}px;' +
            'border: 1px solid;background:red"></div>'
    };
});

这里是调用指令的html

<div id="ng-app" ng-app="app">
    <div mydirective width="100" height="100"></div>
</div>

这是 fiddle http://jsfiddle.net/saP7T/

最佳答案

您可能需要使用 ng-style .这意味着必须使用您的样式设置一个 javascript 对象。有关详细信息,请参阅该页面上的评论。所以,像这样:

angular.module('app').directive('mydirective', function () {
    return {
        replace: true,
        scope: {
            height: '@',
            width: '@'
        },
        template: '<div ng-style="getMyStyle()"></div>',
        link: function(scope, element, attrs) {
            scope.getMyStyle = function () {
                return {
                    width: scope.width + 'px',
                    height: scope.height + 'px',
                    border: '1px solid',
                    background: 'red'
                };
            }
        }
    };
});

Updated fiddle

关于internet-explorer - AngularJs 指令的模板未在 IE9 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15745333/

相关文章:

angularjs - 为什么在调用 element.remove 时没有触发 $destroy?

html - 为什么我的文档模式是: IE7 standards in HTML5 page?

css - IE 11 flex 对齐元素 : center with an absolute positioned div aligns the top of the div not the middle

angularjs - 如何防止 AngularJS 应用程序中重复的 $http 请求?

html - 使用 native 句柄将 CSS 应用于 Angular 指令(自定义或非自定义)

javascript - 如何将一个 View 移动到具有不同路径文件的 Angular 另一个 View ?

javascript - Marker 中的新 Google Maps Symbol 对象使 IE 非常慢

css - 信不信由你,Internet Explorer 的一个 css 问题

javascript - 在 Angular 模板中使用 http cookie 值

javascript - 如何在用户离开而不保存更改时显示警告消息