错误:[$compile:ctreq],Angularjs

Sae*_*aee 0 angularjs

我有一个输入标签如下:

<input type="checkbox" ng-change="swap($parent.$index,$index)" ng-model="checked">
Run Code Online (Sandbox Code Playgroud)

此标记位于嵌套ng-repeat. 当我删除 时ng-model,出现此错误:

错误:[$compile:ctreq] http://errors.angularjs.org/1.6.4/ $compile/ctreq?p0=ngModel&p1=ngChange

ng-change指令是否需要ng-model指令?

Saj*_*ran 6

这里肯定需要 ng-model,因为 ng-change 需要检测模型的变化,

<input type="checkbox" ng-change="swap($parent.$index,$index)" ng-model="checked">
Run Code Online (Sandbox Code Playgroud)

来自文档

ngChange 表达式仅在输入值的更改导致新值变为...时才计算... 注意,该指令需要存在 ngModel。

ng-change Directive