Ng-Checked 默认值未定义
Ng-Checked default value undefined
我想知道:如何让 CHECKBOX 内的 ng-model 的默认值为真?我的代码会选中该框,但每当我评估模型时,它总是说未定义...这是为什么?
<input ng-change="docModel.check()"
type="checkbox"
ng-model="amountSelected"
ng-checked="true" />
要在使用 AngularJS 时定义默认值,只需为控制器中的模型变量赋值:
$scope.amountSelected = true;
根据官方 AngularJS 文档 ngChecked 指令:
Note that this directive should not be used together with ngModel, as this can lead to unexpected behavior
我想知道:如何让 CHECKBOX 内的 ng-model 的默认值为真?我的代码会选中该框,但每当我评估模型时,它总是说未定义...这是为什么?
<input ng-change="docModel.check()"
type="checkbox"
ng-model="amountSelected"
ng-checked="true" />
要在使用 AngularJS 时定义默认值,只需为控制器中的模型变量赋值:
$scope.amountSelected = true;
根据官方 AngularJS 文档 ngChecked 指令:
Note that this directive should not be used together with ngModel, as this can lead to unexpected behavior