Javascript “我如何解决?”;无法读取属性';长度';在CheckWithEletedModel中未定义的;在angularjs?

Javascript “我如何解决?”;无法读取属性';长度';在CheckWithEletedModel中未定义的;在angularjs?,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,如何解决此错误“无法读取CheckWithEletedModel处未定义的属性'length' 当我直接在控制器中添加对象时,它正在工作,但当数据来自api时,我得到了错误 TypeError: Cannot read property 'length' of undefined at checkWithSeletedModel (newbooking.html:404) at new MyCtrlFun (newbooking.html:391) at invoke (angular-1.0.

如何解决此错误“无法读取CheckWithEletedModel处未定义的属性'length'

当我直接在控制器中添加对象时,它正在工作,但当数据来自api时,我得到了错误

TypeError: Cannot read property 'length' of undefined
at checkWithSeletedModel (newbooking.html:404)
at new MyCtrlFun (newbooking.html:391)
at invoke (angular-1.0.1.js:2795)
at Object.instantiate (angular-1.0.1.js:2805)
at angular-1.0.1.js:4620
at angular-1.0.1.js:4201
at forEach (angular-1.0.1.js:117)
at nodeLinkFn (angular-1.0.1.js:4186)
at compositeLinkFn (angular-1.0.1.js:3838)
at compositeLinkFn (angular-1.0.1.js:3841)
var myApp=angular.module('myApp',[]);
//指令('myDirective',function(){});
//工厂('myService',function(){});
myApp.controller(“MyCtrl”,MyCtrlFun);
MyCtrlFun.$inject=[“$scope”、“$filter”、“$timeout”、“$http”];
函数MyCtrlFun($scope、$filter、$timeout、$http){
//******选定列表****
$scope.selectedlist=[“Lumia 735 TS”,“Lumia 510”];
$scope.checkbox_model=[];
$scope.checkbox_list=[];
$scope.submitModel=[];
var子模型=[];
var模型={};
var brandname={};
$scope.finalOutput={
城市:空,
Storename:null,
奥菲丽:空,
报价:空,
总价:空,
子项总价:空,
类别:[]
}
$scope.finalOutput_with NullFilter={};
$scope.checkItems=函数(){
$scope.checkbox_list=[];
$scope.selectedlist=新数组();
for(变量项在$scope.checkbox\u模型中){
如果($scope.checkbox_model[item].isChecked)
{
$scope.selectedlist.push($scope.checkbox\u model[item].name);
$scope.checkbox_list.push($scope.checkbox_model[item]);
}
}
$scope.checkbox\u list.push({offer\u id:$scope.selected\u offer\u id});
//警报(Storename)
/*var m=价格变更供应商($scope.selected\u offer\u id);
如果(!isNaN(m)){
$scope.total_price=$scope.total_price-parseInt(m);
}*/
$scope.checkbox\u list.push({sub\u total:$scope.sub\u total});
checkWithSeletedModel();
$scope.finalOutput.city=$scope.phones[0].city;
$scope.finalOutput_with NullFilter=$scope.finalOutput;
if($scope.finalOutput.Storename==null)
{
$scope.finalOutput.Storename=$scope.phones[0].Storename;
}
if($scope.finalOutput.Offerid==null)
{
删除$scope.finalOutput.Offerid;
}
if($scope.finalOutput.Offer_price==null)
{
删除$scope.finalOutput.Offer\u价格;
}
警报(JSON.stringify($scope.finalOutput));
//******将数据提交到服务器后重新定义FinalOut
$scope.finalOutput={
城市:空,
Storename:null,
奥菲丽:空,
报价:空,
总价:空,
子项总价:空,
类别:[]
}
}
$scope.selectedbrand='Nokia';
$scope.submodel='Lumia';
$http.get('http://19.168.1.4/shop1/)。成功(功能(数据、状态、响应)
{
//$scope.phones=数据
//console.log($scope.phones);
//控制台我得到了一个对象。在这里我添加了我在控制台中得到的东西
$scope.phones=[{
“_id”:{
$oid:“56a9c44f40d0275643cfc04e”
},
“默认值”:[],
“类别”:[
{
“模型”:[
{
“子模型”:[
{
“价格”:“不可用”,
“名称”:“Lumia 735 TS”
},
{
“价格”:“8100”,
“名称”:“Lumia 510”
},
{
“价格”:“9900”,
“名称”:“Lumia 830”
}
],
“名称”:“Lumia”
},
{
“子模型”:[
{
“价格”:“10000”,
“名称”:“Asha 230”
},
{
“价格”:“11999”,
“名称”:“Asha Asn01”
}
],
“姓名”:“阿莎”
}
],
“品牌名称”:“诺基亚”,
“id”:“986745”
},
{
“模型”:[
{
“子模型”:[
{
“价格”:“5000”,
“名称”:“趋势840”
},
{
“价格”:“6999”,
“名称”:“A5”
}
],
“名称”:“银河”
},
{
“子模型”:[
{
“价格”:“12000”,
“名称”:“Asha 230”
}
],
“姓名”:“阿莎”
}
],
“品牌名称”:“三星”,
“id”:“144745”
}
],
“店名”:“之字形手机”,
“Shopid”:“asdef1234”,
“城市”:“班加罗鲁”,
“_v”:0
}
]
});
//----------------------------我们的商店提供----------------------------------------
$http.get('http://19.168.1.4/offers/)。成功(功能(数据、状态、响应)
{
//$scope.offers=数据;
//log($scope.offers);
//控制台我得到了一个对象。在这里我添加了我在控制台中得到的东西
$scope.offers=[
{
id:“as23456”,
“店名”:“之字形手机”,
“Shopid”:“asdef1234”,
“报价信息”:“1000卢比关闭”,
“类别”:[
{
“模型”:[
{
“子模型”:[
{
“价格”:“1000”,
“名称”:“Lumia 735 TS”
}
],
“名称”:“Lumia”
}
],
“品牌名称”:“诺基亚”,
“id”:“986745”
}
],		
},{
id:“de34575”,
“店名”:“之字形手机”,
“Shopid”:“asdef1234”,
“优惠信息”:“500卢比优惠”,
“类别”:[
{
“模型”:[
{
“s
for(var i=0; i<$scope.phones.length; i++)