2017-10-04 7 views
0

「として」私はそれはChromeとFirefoxで正常に動作しますが、IE 11IEのNG-無効な構文

<!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> 

に問題が私なら、私に知らせてくださいNG-無効に問題があると動作しませんありがとうございました。あなたがIE11で動作するプロトタイプの方法trimを追加することができます

答えて

0

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>

+0

私の問題は、文字列に関するものではありませんが、私はコントローラから渡していた値がで更新されません表示 –

+0

、すなわち11はトリム機能をサポートしていません。だから手動で実装する必要があります –

+0

私は例としてトリムを与えたばかりです。それはトリムのためではありません –