【问题标题】:How to checkbox checked default single and multiple checkbox? ng-init="checkboxModel.value=true" its not working如何复选框选中默认的单个和多个复选框? ng-init="checkboxModel.value=true" 它不工作
【发布时间】:2020-10-08 07:03:39
【问题描述】:
<input type="checkbox" ng-model="checkboxModel.value" ng-true-value="'true'" ng-false-value="'false'" ng-click='checkboxClick(checkboxModel.value, index);' ng-init="checkboxModel.value=true" />

【问题讨论】:

    标签: javascript html jquery angularjs angular


    【解决方案1】:

    var demoApp = angular.module('myApp', []);
    demoApp.controller('languageController', function($scope, $http) {
    
        $scope.languages = [
          {id:1, name:'C#'},
          {id:2, name:'MVC'},
          {id:3, name:'SQL'},
          {id:4, name:'AngularJs'},
          {id:5, name:'jQuery'},
          {id:6, name:'Javascript'},
          {id:7, name:'HTML'},
          {id:8, name:'CSS'},
          {id:9, name:'Linq'},
          {id:10, name:'EntityFramework'}
        ];
        
        $scope.defaultSelected = [
          {id:2, name:'MVC'},
          {id:4, name:'AngularJs'}
        ];
        
        $scope.checkID = function(name){
          var dat = $scope.defaultSelected.find(v=> v.name === name);
          if(dat) {return true }else{ return false}
        }
    
        $scope.submit = function() {
            $scope.result = $scope.loopData;
        };
    
    });
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    
    
    <body ng-app="myApp">
            <div class="wrapper wrapper-content middlealigen col-sm-12" ng-controller="languageController">
                
                <div ng-repeat="language in languages">
                    
                    <input type="checkbox" ng-model="language.checked" id="language{{$index}}" ng-checked="checkID(language.name)" />
                    
                    <label for="language{{$index}}" ng-bind="language.name"></label>
                </div>
    
            </div>
        </body>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多