小编Sim*_*ive的帖子

Angularjs ngDisabled比较表达式未正确评估

我试图在angularjs应用程序中启用或禁用按钮,具体取决于两个文本字段的比较是否为true或false.我在下面提供了示例代码,并在此处提供了一个plunker http://plnkr.co/edit/rzly8hy21048YGzsx2gW?p=preview

正如您所看到的,当您输入字符串以匹配存储的字符串时,表达式会正确计算,但按钮永远不可用.

任何帮助,将不胜感激.

这是HTML

    <!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.2.x" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js" data-semver="1.2.16"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <button ng-click="updateCounter()">Increment count</button>
    <input type="text" ng-model="inputfield">
    <input type="button" value="Continue" ng-disabled="{{inputfield !== startertext}}">
    <br>startertext: {{startertext}}
    <br>nputfield: {{inputfield}}
    <br>test: {{inputfield !== startertext}}

  </body>


</html>
Run Code Online (Sandbox Code Playgroud)

而Javascript文件如下.

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.startertext = 'hello world';
});
Run Code Online (Sandbox Code Playgroud)

javascript expression button disabled-input angularjs

4
推荐指数
2
解决办法
2万
查看次数