ng-repeat不起作用的复选框

时间:2016-10-31 09:24:52

标签: angularjs checkbox

当有人点击我需要调用AngularJs中的方法时,我得到了一个级别列表。当我点击复选框时没有发生任何事情,但是当我点击ng-repeat之外的复选框时工作正常。这是我的代码。

$(window).scroll(function () {
  if ($(document).scrollTop() === 0) {
    $('#top-wrapper').removeClass('sticky ');
  } else {
    $('#top-wrapper').addClass('sticky ');
  }
});

$(document).ready(function () {
    $(function () {
      var nav = $('#secondary-nav');
      if (nav.length) {
          var stickyNavTop = nav.offset().top;
          $(window).scroll(function () {
              if ($(window).scrollTop() > stickyNavTop) {
                  $('#secondary-nav').addClass('sticky');
              } else {
                  $('#secondary-nav').removeClass('sticky');
              }
          });
      }
    });
});

这是我的控制器代码:

<div class="col-md-4">
                        <label>Select Level:</label>
                        <div ng-repeat="level in vm.Levels | filter: {Workshop:true}">


                            <div class="i-checks">
                                <input type="checkbox" ng-model="level.Name" id="{{'level-'+ level.SkillId}}" icheck />
                                <label class="control-label">
                                    {{level.Name}}
                                </label>
                            </div>
                        </div>
                        <input type="checkbox" />

                    </div>

提前致谢。

1 个答案:

答案 0 :(得分:1)

// Code goes here

angular
	.module('myApp',[])
	.run(function($rootScope){
		$rootScope.title = 'myTest Page';
	})
	.controller('testController', ['$scope', function($scope){
	  
		$scope.Levels  = [{Name:'string1',SkillId:1},{Name:'string2',SkillId:2},{Name:'string3',SkillId:3}]
		
	}])
<!DOCTYPE html>
<html data-ng-app="myApp">

<head>
  <link rel="stylesheet" href="style.css">
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
  <script src="script.js"></script>
</head>

<body data-ng-controller="testController">

  <div class="col-md-4">
    <label>Select Level:</label>
    <div ng-repeat="level in Levels">

      <div class="i-checks">
        <input type="checkbox"  id="{{'level-'+ level.SkillId}}" icheck />
        <label class="control-label">
          {{level.Name}}
        </label>
      </div>
    </div>
    <input type="checkbox" /> checkbox outside

  </div>

</body>

</html>