简体   繁体   English

angular.js:12520 TypeError:无法读取r。$ scope.insertvalue处未定义的属性'option1'

[英]angular.js:12520 TypeError: Cannot read property 'option1' of undefined at r.$scope.insertvalue

I working on a project called gold loan management system.In which i want to insert the customers ornament's list and it's weight,Insertion is done by using http.post(),I want to insert more than one ornament, so i used a for loop.I can insert the values into the database ,but showing the following error message. 我正在从事一个名为“黄金贷款管理系统”的项目。我要在其中插入客户装饰品的清单及其权重,使用http.post()完成插入,我想插入多个装饰品,因此我使用了我可以将值插入数据库,但显示以下错误消息。

Ornament insertion 装饰插入

index.html 的index.html

<form  class="form-inline form-group">
   <fieldset  data-ng-repeat="choice in    choices">
      <div class="col-xs-3">
         <div class="form-group">
            <select  class="form-control"    id="optioin1"  ng- model="choice.option1" >
               <option value="Ring"   >Ring</option>
               <option value="Earings" >Earings</option>
               <option value="Chains">Chains</option>
               <option value="Necklaces">Necklaces</option>
               <option value="Bangles">Bangles</option>
            </select>
         </div>
         {{choice.option1}}
      </div>
      <div class="col-xs-4">
         <div class="input-group">
            <input type="number" step="0.01" ng-model="choice.weight" class="form-control" placeholder="Weight" aria-describedby="basic-addon2">
            <span class="input-group-addon" id="basic-addon2">gm</span>
         </div>
      </div>
      <div class="col-xs-4 pull-right">
         <button class="btn btn-default" ng-show="$last"  ng-click="removeChoice() "><span class="glyphicon glyphicon-minus" aria-hidden="true"></span></button>
         <button class="btn btn-default"  ng-show="$last" ng-click="addNewChoice()"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
      </div>
   </fieldset>
</form>

dashboard.js dashboard.js

app.controller('dashboardCtrl', function($scope,$rootScope,$http) {
    $scope.date = new Date();
    $scope.place='Kovilloor';
    $scope.choices = [{id: 'choice1'}];
    $scope.addNewChoice = function() {
        var newItemNo = $scope.choices.length+1;
        $scope.choices.push({'id':'choice'+newItemNo});
    };    
};
$scope.insertvalue = function(){
    var gl=($scope.GLID.GLID-0);
    $scope.gli=gl+1;
    for(var i=0;i<=$scope.choices.length;i++){
        $http.post("php/insertornament.php",   {'GLID':$scope.gli,'ORNAMENT':$scope.choices[i].option1,//Error
            'WEIGHT':$scope. choices[i].weight
        })
    }
}; 

Looks like it should be less-than rather than less-than-or-equal-to : 看起来它应该小于 或小于或等于

Change: 更改:

for(var i=0;i<=$scope.choices.length;i++){

To: 至:

for(var i=0; i < $scope.choices.length; i++){

The offended part is this: 冒犯的部分是这样的:

'ORNAMENT':$scope.choices[i].option1

because i will become out of bounds and so $scope.choices[i] will therefore be undefined: 因为i将变得越界,因此$scope.choices[i]将因此未定义:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 angular.js:12520 TypeError:无法读取未定义的属性&#39;post&#39; - angular.js:12520 TypeError: Cannot read property 'post' of undefined $ window.location.href(angular.js:12520 TypeError:无法设置未定义的属性&#39;href&#39;) - $window.location.href (angular.js:12520 TypeError: Cannot set property 'href' of undefined) angular.js:13550 TypeError:无法读取未定义的属性“编译”? - angular.js:13550 TypeError: Cannot read property 'compile' of undefined? angular.js:14110 TypeError:无法读取undefined的属性&#39;push&#39; - angular.js:14110 TypeError: Cannot read property 'push' of undefined Angular.js:10671 TypeError:无法读取未定义的属性 - Angular.js:10671 TypeError: Cannot read property of undefined 即时通讯收到错误。 angular.js:13550 TypeError:无法读取未定义的属性&#39;$ invalid&#39; - im getting error. angular.js:13550 TypeError: Cannot read property '$invalid' of undefined Angular.js $ http.post TypeError:无法读取未定义的属性“data” - Angular.js $http.post TypeError: Cannot read property 'data' of undefined 我不断收到此错误“ angular.js:TypeError:无法读取未定义的属性&#39;pages&#39;” - I keep getting this error “angular.js:TypeError: Cannot read property 'pages' of undefined” angular.js:13550 TypeError:无法设置未定义的属性“people” - angular.js:13550 TypeError: Cannot set property 'people' of undefined angular.js:13920 TypeError:无法读取null的属性&#39;push&#39; - angular.js:13920 TypeError: Cannot read property 'push' of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM