Reputation: 7113
if value is not selected for ng-model selectedFileSize
its throwing error TypeError: Cannot read property 'size' of undefined
when i click on button startRecording
. How can i resolve this problem ?
main.html
<div class="col-md-3">
<select class="form-control" ng-model="selectedFileSize" ng-options="item as item.value for item in FileSizeOptions" ng-change="onSizeChange()"><option value="">Select</option></select>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-primary" ng-click="startRecording()">Start Recording</button>
</div>
ctrl.js
if (($scope.selectedFileSize.size !== "") || ($scope.selectedFileSize !== undefined)) {
//logic here
}
Upvotes: 2
Views: 748
Reputation: 193291
You need to check that selectedFileSize
is populated before checking selectedFileSize.size
:
if ($scope.selectedFileSize && $scope.selectedFileSize.size) {
//logic here
}
Upvotes: 3