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

Sim*_*ive 4 javascript expression button disabled-input angularjs

我试图在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)

pix*_*its 9

删除ng-disabled属性周围的curles.

  • 感觉自己像个白痴,一直在修补它并实际加入它们.工作完美无瑕! (4认同)

Alm*_*ron 5

这是它为你的插件工作的方式:

<input type="button" value="Continue" ng-disabled="startertext != inputfield">
Run Code Online (Sandbox Code Playgroud)

不要忘记删除控制器中的额外curlie(当我在编辑器中打开它时标记错误符号).