显示消息功能不起作用

时间:2013-12-28 00:16:07

标签: angularjs

尝试我的第一个ng-show示例。我怎样才能使这个功能起作用?

HTML

<body ng-app="myApp" ng-cloak>
    <div ng-controller="todocontroller">
        <button ng-click="addCount()">Increment</button>count:{{count}}
        <div ng-visible="msgvisible">too many clicks</div>
    </div>
</body>

JS

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

 function todocontroller($scope) {
     $scope.firstname = "";
     $scope.lastname = "";
     $scope.count = 0;

     $scope.addCount = function () {
         $scope.count++;
     }

     $scope.msgvisible = function () {
         if ($scope.count > 5) {
             return true;
         } else {
             return false;
         }
     }
 }

的jsfiddle:http://jsfiddle.net/dingen2010/V548j/2/

1 个答案:

答案 0 :(得分:0)

您希望将函数msgvisible的结果传递给ngShow。现在,您将函数本身传递给属性ngVisible

所以改变这个:

<div ng-visible="msgvisible">too many clicks</div>

对此:

<div ng-show="msgvisible()">too many clicks</div>

您已设置:updated fiddle