Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';不要在ngRepeat-Angularjs中使用ngChange_Javascript_Angularjs_Checkbox_Angularjs Ng Repeat - Fatal编程技术网

Javascript Can';不要在ngRepeat-Angularjs中使用ngChange

Javascript Can';不要在ngRepeat-Angularjs中使用ngChange,javascript,angularjs,checkbox,angularjs-ng-repeat,Javascript,Angularjs,Checkbox,Angularjs Ng Repeat,我正在使用ngRepeat生成一个复选框字段集 我的做法如下: <fieldset id="country_select" ng-controller="CountriesListController"> <span ng-repeat="country in countries"> <label> <input type="checkbox" id="country.name" ng-chan

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

ng更改将需要
ng型号
。复选框上缺少ng模型


检查此项以了解工作示例。

要小心使用
ngChange
。就我而言,当我打算使用
data ng click时,我的手指和眼睛有点太快了,没有抓住Intellisense选择
data ng change


我敢肯定,在键入
data-ng-c
之后,我只看到了一个条目(data ng click);但可能Intellisense在显示其他选项时有点慢,当我点击[Tab]时,首先选择了字母顺序…

检查浏览器控制台是否有错误。请将整个代码粘贴到JSFIDDLE中。我已经为您添加了我的控制台错误,谢谢!您可能知道ng change指令为什么需要ng model吗?我在Angular文档中看到的是:注意,该指令要求存在ngModel。它是必需的,因为它在内部检查是否为ng model提交了新值。如果是,则只对ng-change进行评估。此外,需要ng模型来维护控件的状态,如脏、无效等,这在表单提交时非常有用,或者需要ng模型,如果您希望将所选复选框的值访问到范围中。哦,这是完全有意义的。谢谢你教我更多关于角度的知识。
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