Angularjs - How to check undefined from select value -
how check or trap undefined
select value select tag. prevent user forget select selection box.
have been trying below js still show undefined error in console log , not alert show in browser.
code
<select ng-model="add.partcode" ng-options="x.part_no x in distictpartcode" ng-change="getlocation()"> <option value="">please select partcode</option> </select>
js
if(!angular.isundefinedornull($scope.add.partcode.part_no )){ var partcode = $scope.add.partcode.part_no; }else { var alertpopup = $ionicpopup.alert({ title: 'error ...', template: 'please choose part code first.' }); }
or
if(!$scope.add.partcode.part_no){ var partcode = $scope.add.partcode.part_no; }else { var alertpopup = $ionicpopup.alert({ title: 'error ...', template: 'please choose part code first.' }); }
error in console.
typeerror: cannot read property 'part_no' of undefined
that's becuse $scope.add.partcode
become object when object selected otherwise it's null
, null
don't have property access them using .
try this
if (!$scope.add.partcode) { var alertpopup = $ionicpopup.alert({ title: 'error ...', template: 'please choose part code first.' }); } else { var partcode = $scope.add.partcode.part_no; }
Comments
Post a Comment