【发布时间】:2015-03-13 12:50:39
【问题描述】:
我正在使用 ngRepeat 生成复选框字段集。
我这样做如下:
<fieldset id="country_select" ng-controller="CountriesListController">
<span ng-repeat="country in countries">
<label>
<input type="checkbox" id="country.name" ng-change="locationAdd(country.name)">
{{country.name}}
</label><br/>
</span>
</fieldset>
但是由于某种原因,将 ngChange 指令添加到我的复选框会导致我的 ng-repeat 输出仅显示一个复选框,如下所示:
复选框 {{country.name}}
当我将 ngChange 更改为 ngClick 时,我的 ngRepeat 循环有效。
所以我的问题是:为什么 ngChange 不能与 ngRepeat 一起使用,但 ngClick 在插入到我的复选框输入中时会起作用
我在控制台中收到以下错误:
Error: [$compile:ctreq] Controller 'ngModel', required by directive 'ngChange', can't be found!
http://errors.angularjs.org/1.3.7/$compile/ctreq?p0=ngModel&p1=ngChange
at REGEX_STRING_REGEXP (http://localhost:9000/bower_components/angular/angular.js:63:12)
at getControllers (http://localhost:9000/bower_components/angular/angular.js:7535:19)
at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7724:33)
at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7073:13)
at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7076:13)
at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7076:13)
at publicLinkFn (http://localhost:9000/bower_components/angular/angular.js:6952:30)
at $get.boundTranscludeFn (http://localhost:9000/bower_components/angular/angular.js:7091:16)
at controllersBoundTransclude (http://localhost:9000/bower_components/angular/angular.js:7747:18)
at ngRepeatAction (http://localhost:9000/bower_components/angular/angular.js:24524:15)angular.js:11592 (anonymous function)angular.js:8542 $getangular.js:14241 $get.Scope.$digestangular.js:14486 $get.Scope.$applyangular.js:9644 doneangular.js:9834 completeRequestangular.js:9775 requestLoaded
【问题讨论】:
-
检查浏览器控制台是否有错误。
-
请将整个代码粘贴到jsfiddle中
-
我已经为你们添加了我的控制台错误
标签: javascript angularjs checkbox angularjs-ng-repeat