How can i solve "Cannot read property 'length' of undefined at checkWithSeletedModel" in angularjs?
how can i solve this error "Cannot read property 'length' of undefined at checkWithSeletedModel".
when i add object directly in controller its working but when data coming from api i am getting error
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 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)
here you are trying to access the length of $scope.phones variable. But you have defined $scope.phones inside the success callback of your api call. But your api calls are all failing. therefore success callback are never getting called and therefore $scope.phones is always undefined. Thus you are getting error that `cannot read length of undefined'.
Asked in February 2016Viewed 3,593 timesVoted 13Answered 1 times