【问题标题】:checkbox with ng-repeat not working带有 ng-repeat 的复选框不起作用
【发布时间】:2016-10-31 18:45:23
【问题描述】:

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

<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>

这是我的控制器代码:

(function () {
            'use strict';
            var controllerId = 'SeriesEditor';
            angular.module('app').controller(controllerId, ['apiFactory', "$filter", SeriesEditor]);

            function SeriesEditor(wfapi, $filter) {
                var vm = this;

                vm.Init = function () {                   
                    vm.Levels = [];                  
                }

     vm.loadLevelsForSeries = function () {

                    var mReq = new Models.services.LevelListRequest();
                    api.get(mReq)
                        .then(function (data) {
                            vm.Levels = data.Results;
                        });
                }
     }
        })();

提前致谢。

【问题讨论】:

  • 控制器代码?

标签: angularjs checkbox


【解决方案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>

【讨论】:

    猜你喜欢
    • 2017-09-28
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-11
    相关资源
    最近更新 更多