I have an issue with ng-disabled it works fine with chrome and firefox but the problem with IE 11
我有一个ng-disabled的问题它与chrome和firefox工作正常,但IE 11的问题
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My first app</title>
</head>
<body ng-app="myApp" ng-controller="myController as vm">
<input type="text" ng-model="vm.name" />
<button ng-disabled="vm.isBtnDisabled()">Button</button>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script>
var app=angular.module("myApp",[]);
app.controller("myController",["$scope", function($scope){
this.name="";
this.isBtnDisabled=function(){
return this.name.trim().length==0;
}
}]);
</script>
</body>
</html>
Please let me know if i had made any mistake, Thanks.
如果我犯了任何错误,请告诉我,谢谢。
1 个解决方案
#1
0
you can add prototype method trim
to work with IE11
你可以添加原型方法修剪来使用IE11
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
var app=angular.module("myApp",[]);
app.controller("myController",["$scope", function($scope){
this.name="";
this.isBtnDisabled=function(){
return this.name.trim().length==0;
}
}]);
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController as vm">
<input type="text" ng-model="vm.name" />
<button ng-disabled="vm.isBtnDisabled()">Button</button>
</div>
#1
0
you can add prototype method trim
to work with IE11
你可以添加原型方法修剪来使用IE11
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
var app=angular.module("myApp",[]);
app.controller("myController",["$scope", function($scope){
this.name="";
this.isBtnDisabled=function(){
return this.name.trim().length==0;
}
}]);
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController as vm">
<input type="text" ng-model="vm.name" />
<button ng-disabled="vm.isBtnDisabled()">Button</button>
</div>