类型错误:无法读取 ng-repeat 的未定义属性
TypeError: Cannot read property of undefined for ng-repeat
我正在尝试让ng-repeat在收据中重复项目列表。我有这个工作的编辑功能,但我无法让添加页面工作,因为它显示:
TypeError: Cannot read property 'spiffs' of undefined
这是导致它的代码:
$scope.model.spiffs = [];
$scope.model.spiffs = [{ spiff_id: 0, receipt_id: 0, product_id: 0, spiff_amt:0, quantity: 1, active: true, note: null }];
起初它是第二行,但我想我会尝试将 $scope.model 制作为空数组以尝试提前声明数组,我尝试了不同的变体,我想我只是错过了一些简单的东西。当我没有任何初始输入来填充表单时,我需要做什么来设置我的表单以ng重复一组字段?之后,我是否能够通过简单的$scope.model
调用获取所有表单数据并将其发送到我的 API?
这是希望受到影响的 HTML:
<div class="col-xs-10 col-xs-offset-2" ng-repeat="item in model.spiffs">
<div ng-hide="item.active === false">
<div class="col-xs-4 form-group">
<select name="productID" ng-model="item.product_id" required="" ng-change="changeSpiffProduct($index)" class="form-control"
ng-options="product.product_id as product.model_number + ' ' + product.name for product in products">
</select>
</div>
<div class="col-xs-2 form-group">
<input name="spiff_sale_price" type="text" placeholder="" ng-model="item.quantity" class="form-control input-md">
</div>
<div class="col-xs-2 form-group">
<p name="spiff_amt" class="form-control-static">{{item.spiff_amt | currency: "$"}}</p>
</div>
<div class="col-xs-2 form-group">
<p name="spiff_total" class="form-control-static">{{item.spiff_amt * item.quantity | currency: "$"}}</p>
</div>
<div class="col-xs-2 form-group">
<button class="btn btn-danger" novalidate ng-click="removeSpiff($index)"><i class="fa fa-minus"></i></button>
</div>
</div>
</div>
提前非常感谢您的帮助!
您需要先定义范围的属性"模型",然后才能为其分配"spiff"。您可以通过两种方式执行此操作:
$scope.model = {};
//OR:
$scope.model = {
spiffs: []
};
你正在写$scope.model.spiffs。这里的模型是未定义的,因此存在错误。
类型错误:无法读取未定义的属性"spiffs"
你需要先初始化$scope.model,像这样
$scope.模型 = {}
现在,由于$scope.model 不是未定义的,因此您可以添加一个属性。
希望对您有所帮助。
相关文章:
- 当ng repeat上的复选框具有必需的属性时,角度ng模型将变为未定义
- AngularJS ng repeat显示原型函数未定义
- AngularJS -- 创建自定义数据绑定和 ng-repeat
- 如何仅在文本字段中有值时才将自定义过滤器应用于 ng-repeat
- 未捕获的错误:使用 ng-repeat 时出现 [$injector:modulerr]
- $compile和ng repeat未返回正确的元素
- 错误:[ng:areq]参数'CompanyCtrl'不是函数,未定义
- 断言var集通过<输入ng模型>不是未定义的
- ng模型值总是未定义的
- 类型错误:无法读取 ng-repeat 的未定义属性
- NG-model 未定义多种方式无法从文本框获取文本
- ng-repeat中的ng模型变得未定义
- AngularJS:ng repeat未在作用域指令内执行
- Angular Ajax调用,ng-repeat未显示
- Ng-model未定义的空字符串
- 在Angular.js中使用ng-repeat自定义过滤器
- ng-repeat中的动态ng-模型未定义
- AngularJS - form inside ng-repeat在控制器中未定义
- Angular ng repeat未正确显示数据
- Typescript方法的ng-repeat自定义过滤器没有按预期的方式运行