IE ng-disabled无法使用“as”语法

时间:2017-10-04 10:54:16

标签: angularjs angularjs-ng-disabled

我有使用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>

如果我犯了任何错误,请告诉我。谢谢。

1 个答案:

答案 0 :(得分:0)

您可以添加原型方法scope.$watch以使用IE11

changes

&#13;
&#13;
trim
&#13;
String.prototype.trim = function() {
     return this.replace(/^\s+|\s+$/g, ''); 
}
&#13;
&#13;
&#13;