angularjs ng-option ie issue解决方案
最近遇见angularjs 在IE上当使用ng-options作为select的选项数据源,并且被套在ng-switch(ng-transclude)之类的,当angular上得ng-options数据源model改变后,在IE上并不渲染。
在一阵的测试和阅读相关文档后最后确认为:因为ng-switch(ng-transclude)是为了使其scope为原来的父scope,在父scope上生成了DOM后才克隆(cloneNode)到指定的指令位置。然而IE在对于select克隆的节点,不会主动去触发重绘,所以才有了上面的issue。
问题确定了,那我们所需要做的就是手动的去触发让IE对Select重绘,尝试了很多办法后最终确认有效的是:首先在options上用原生js去添加一个option,在马上移除掉这个option,所以解决方案如下:
angular.module('ie.select', [])
.directive('ieSelectFix', [
function () {
return {
restrict: 'A',
require: 'select',
link: function (scope, element, attributes) {
var isIE = document.attachEvent;
if (!isIE) return;
var control = element[0];
scope.$watch(attributes.ieSelectFix, function () {
//it should be use javascript way, not jquery way.
var option = document.createElement("option");
control.add(option, null);
control.remove(control.options.length - 1);
});
}
}
}
]);
使用方式如下:
<select ie-select-fix="options" ng-model="demos" class="form-control"
ng-options="currOption.value as currOption.text for currOption in options">
<option value="" default>Select</option>
</select>
我也在我的github专门创建了一个针对angularjs在IE上issue的项目,收录了这个指令,在后续也会加入我所遇见的angularjs关于ie的issue,也希望大家帮助完善这个项目,让我们的angularjs程序在IE工作的更美好,让我们这些辛苦的程序猿也少一点加班时间,多一点陪家人,泡咖啡的时间。哈哈。
github项目地址:https://github.com/greengerong/angular-ie-enhancer
angularjs ng-option ie issue解决方案的更多相关文章
- angularjs 页面缓存及动态刷新解决方案
一.准备工作 框架:angularjs ui组件库:ionic1 二.页面缓存cache 路由设置cache参数,true为缓存,false为不缓存,代码如下: angular.module('app ...
- Part 6 AngularJS ng repeat directive
ng-repeat is similar to foreach loop in C#. Let us understand this with an example. Here is what we ...
- part 4 AngularJS ng src directive
- AngularJs ng-repeat重复项异常解决方案
ng-repeat="v in arr track by $index" <!DOCTYPE html> <html lang="en"> ...
- 常用的Issue解决方案(EF框架)
1.提交出错:ObjectStateManager 中已存在具有同一键的对象. ObjectStateManager 无法跟踪具有相同键的多个对象. 遇到此问题,首先要确定的是主键是否赋值,以及 ...
- Part 15 AngularJS ng init directive
The ng-init directive allows you to evaluate an expression in the current scope. In the following e ...
- [AngularJS] AngularJS系列(1) 基础篇
目录 什么是AngularJS? 为什么使用/ng特性 Hello World 内置指令 内置过滤器 模块化开发 一年前开始使用AngularJS(以后简称ng),如今ng已经出2了.虽说2已完全变样 ...
- 从angularJS看MVVM
javascript厚积薄发走势异常迅猛,导致现在各种MV*框架百家争雄,MVVM从MVC演变而来,为javascript注入了全新的活力.我工作的业务不会涉及到angularJS[ng]这么重量级的 ...
- [Angularjs]angular ng-repeat与js特效加载先后导致的问题
写在前面 最近在项目中遇到这样的一个前端的bug,在ng-repeat中绑定的图片,有一个晃动的特效,在手机端浏览的时候,图片有时候会正常展示,有时就展示不出来.当时猜测是因为angularjs与特效 ...
随机推荐
- 炫酷CSS
<!DOCTYPE html><!--To change this license header, choose License Headers in Project Propert ...
- [php-src]窥探Php内核中的数组与面向对象
内容均以php5.6.14为例. 扩展中定义一个类有以下四步: #1. 声明一个存储类信息的指针. zend_class_entry *errs_ce; #2. 定义方法的参数信息,类的方法实现. Z ...
- 关于myeclipse的破解的问题
myeclipse的破解的问题,也是在网上down 了一下,发现并不需要找到什么注册的软件都可以自动完成的哦! 博客地址:http://blog.csdn.net/fuxiaohui/article/ ...
- iptables示例
[root@iZ23um2lv3tZ ~]# more /etc/sysconfig/iptables # Generated by iptables-save v1. :: *filter :INP ...
- android书籍
教程 源码下载 高薪招聘 Cocos2d-x 博客 签到 视频教程 wiki 帖子 搜索 热搜:二维码定时器手电筒滑块斗地主书架定位买手机聊天游戏开发游戏股票查询机顶盒通话记录二维码扫描振动器 ...
- JS各种算法小例子
<!DOCTYPE html><html><head> <title>js</title> <meta charset=& ...
- Red hat 6.4下面的qt安装
运行环境:Red hat 6.4 去官网下载qt5.2并且安装 当启动的时候会出现如下错误 核心载入失败: /opt/Qt5.2.0/Tools/QtCreator/lib/qtcreator/plu ...
- js复制内容加版权声明代码
$("body").on('copy', function (e) { if (typeof window.getSelection == "undefined" ...
- 替换CENTOS自带的yum源为网易163镜像源
首先确保你的系统是centos5或者centos6 先备份你系统自带的repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/Cent ...
- Angular常用功能
1.默认选择让第0个元素的class为active ng-class="{active:$index == 0}" 2.指令的例子 <!DOCTYPE html> &l ...