gpt4 book ai didi

javascript - 无法在 ngRepeat 中使用 ngChange - Angularjs

转载 作者:搜寻专家 更新时间:2023-11-01 05:04:51 24 4
gpt4 key购买 nike

我正在使用 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

最佳答案

ng-change 需要 ng-model。您在复选框上缺少 ng-model

检查这个plunker工作示例。

关于javascript - 无法在 ngRepeat 中使用 ngChange - Angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27958163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com