我将自己的标签转换为输入。 我可以使用select选择readonly / disable for input。 我做的。有用。但不是在ie)))。
我阅读了Angular和IE8的官方文档。 我加了。但我的应用程序在ie8中不起作用。
我无法添加只读/禁用属性(readonly =“readonly”和disabled =“disabled”)
<!DOCTYPE html>
<html xmlns:ng="angularjs.org" id="ng-app" ng-app="dir">
<head>
<!--[if lt IE 8]>
<script src="html5shiv.js"></script>
<![endif]-->
<!-- Internet Explorer AngularJS element creation -->
<!--[if lte IE 8]>
<script>
document.createElement('dhtmlxdate');
</script>
<script src="http://cdnjs.cloudfare.com/ajax/libs/json3/3.2.4/json3.min.js"></script>
<![endif]-->
<meta charset="utf-8" />
<title>ie8</title>
</head>
<body>
<tag mode="{{mode}}"></tag>
<select ng-model="mode">
<option>disabled</option>
<option>readonly</option>
</select>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.1.3/angular.min.js"></script>
<script>
var myapp = angular.module("dir", []);
myapp.directive('tag', function(){
return {
restrict: 'E',
replace: true,
transclude: true,
scope: false,
template: '<input type="text" />'
,
link: function(scope, element, attrs) {
attrs.$observe('mode', function(value) {
switch(value) {
case "disabled":
//attrs.$set('disabled', 'disabled');
element.attr('disabled', 'disabled');
element.removeAttr('readonly');
break;
case "readonly":
//attrs.$set('readonly', 'readonly');
element.attr('readonly', 'readonly');
element.removeAttr('disabled');
break;
}
});
}
};
});
</script>
</body>
</html>
答案 0 :(得分:0)
首先,如果你想避免将来遇到巨大的麻烦,特别是如果你需要IE支持,最好建议你手动引导你的Angular应用程序:
angular.element(document).ready(function() {
angular.bootstrap(document, ['yourAppName']);
});
至于你的实际问题,两者都是“只读”&#39;并且&#39;禁用&#39;属性是布尔属性,这意味着您不必为它们设置值,因为只要它们出现在元素上,它们就会生效。
也就是说,如果您想在输入上有条件地设置它们,我建议您使用ngReadonly和ngDisabled