Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
相当于jQuery的AngularJS:选中代码_Angularjs - Fatal编程技术网

相当于jQuery的AngularJS:选中代码

相当于jQuery的AngularJS:选中代码,angularjs,Angularjs,我想在选中一个或多个复选框时显示带有选项的div,但我似乎无法确定ng show=”“代码应该是什么。这段jQuery代码的AngularJS等价物是什么 $('.复选框:选中')。长度>0如下所述: 如果表达式为truthy,则显示或隐藏元素 分别 所以如果你想找像 <input type="checkbox" ng-model="boolExpr" /> <div ng-show="boolExpr"></div> 没有那么优雅,但也许你可以用这个:

我想在选中一个或多个复选框时显示带有选项的div,但我似乎无法确定
ng show=”“
代码应该是什么。这段jQuery代码的AngularJS等价物是什么

$('.复选框:选中')。长度>0

如下所述:

如果表达式为truthy,则显示或隐藏元素 分别

所以如果你想找像

<input type="checkbox" ng-model="boolExpr" />

<div ng-show="boolExpr"></div>

没有那么优雅,但也许你可以用这个:

<!doctype html>
<html ng-app="app">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js"></script>
    <script>
        var app = angular.module('app', []);
        app.controller('MyCtrl', function ($scope) {
            $scope.options = [
              {'title' : 'Title1', 'value' : 'A'},
              {'title' : 'Title2', 'value' : 'B'},
              {'title' : 'Title3', 'value' : 'C'}
            ];

            $scope.checkboxes = {};

            $scope.showMessage = function () {                  
              for (var key in $scope.checkboxes) {
                if ($scope.checkboxes[key] === true) return true;
              }                  
              return false;
            }
        });                        
    </script>
  </head>
  <body>
    <div ng-controller="MyCtrl">         
      <label ng-repeat="option in options">
        <input
          type="checkbox"
          value="{{option.value}}"
          ng-model="checkboxes[option.value]"
        > {{option.title}}
      </label>      

      Options: {{checkboxes|json}}<br>
      Show message: {{showMessage()|json}}<br>
      <div ng-show="showMessage()">
        hey
      </div>          
    </div>
  </body>
</html>

var-app=angular.module('app',[]);
应用程序控制器('MyCtrl',函数($scope){
$scope.options=[
{'title':'Title1','value':'A'},
{'title':'Title2','value':'B'},
{'title':'Title3','value':'C'}
];
$scope.checkbox={};
$scope.showMessage=函数(){
for(变量键在$scope.checkbox中){
if($scope.checkbox[key]==true)返回true;
}                  
返回false;
}
});                        
{{option.title}}
选项:{{复选框| json}}
显示消息:{{showMessage()| json}}
我找到了我的解决方案:

对于我使用的复选框:

<div ng-repeat="item in items">

<input type="checkbox" ng-model='item.selected' />

</div>

ng show=”“
ng show=“(项目|过滤器:{selected:true}).length”

谢谢你的回答