简体   繁体   English

Angular 1.3单向绑定IE8支持

[英]Angular 1.3 one-way binding IE8 support

I know angular has stopped supporting IE8 in version 1.3, but with the introduction of the one-way binding it's the only thing at the moment that seems to be breaking my page. 我知道angular已停止在1.3版中支持IE8,但是随着单向绑定的引入,这是目前看来唯一的一件事。 I've successfully loaded version 1.2.9 for IE8 only and have every other browser uses 1.3, but the issue I am facing at the moment is that the one way bindings "::" are still being written/displayed out in the html. 我已经成功加载了仅适用于IE8的1.2.9版本,并且所有其他浏览器都使用1.3,但是我目前面临的问题是绑定“ ::”仍在html中写入/显示。 So what I am trying to figure out is a way that I can run a search and replace function over the html to remove the "::" in IE8 before angular runs? 因此,我试图找出一种可以在html上运行搜索和替换功能以删除IE8中“ ::”的方法,以便在运行角度之前?

Current bindings look like: 当前绑定看起来像:

{{ ::day.Stuff }}

What I would like to them look like before angular runs 我想他们在弯角跑之前的样子

{{ day.Stuff }}

Here's a build of Angular 1.3 with IE8 support: https://github.com/fergaldoyle/angular.js-ie8-builds 这是带有IE8支持的Angular 1.3的构建: https : //github.com/fergaldoyle/angular.js-ie8-builds

So you won't have to load a different versions of Angular for different browsers. 因此,您不必为不同的浏览器加载不同版本的Angular。

Not that it would not be a solution to replace every :: binding, but I don't think it would be an efficient one or pretty for that matter. 并不是说替换每个::绑定不是一种解决方案,但是我认为这不是一个有效的解决方案。 If IE8 support is crucial for you, I would suggest using this very popular bind once library: https://github.com/Pasvaz/bindonce . 如果IE8支持对您至关重要,那么我建议您使用此非常流行的一次绑定库: https : //github.com/Pasvaz/bindonce I've used it before 1.3 came along and it served me well. 在1.3出现之前我已经使用过它,它对我很有用。

you could use regex in directive to do it quite simple actually. 您实际上可以在指令中使用regex使其非常简单。 Make sure set terminal to true, if not it will return error. 确保将terminal设置为true,否则将返回错误。

angular.module('fixme').directive('regexDirective', function ($compile) {
  return {
    restrict: 'AE',
    terminal:true,
    link: function(scope, element, attr)  {
        var dirty = element[0].innerHTML;
        var str = dirty.replace(/[::]/g, "");
        var ele = $compile('<div>'+str+'</div>')(scope);
        element.replaceWith(ele);
    }
}

}) })

in the controller. 在控制器中。

angular.module('fixme', []).controller('demoController', ['$scope', function($scope) {
    $scope.day = {Stuff: 'boring'}
    //console.log($scope.day.Stuff)

}]); }]);

in html 在HTML

<body ng-controller="demoController">
   <div regex-directive>{{ ::day.Stuff }}</div>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM