Clean code will be less messy
Here I am using a simple corner shape. Everything works fine. I have a watch group EndDateFrom
and EndDateTo
datepickers. When it is defined, I log the value to the console. I am creating an expression based on my if conditions if the value is defined from datepickers. But I feel like my code is a little messy. Is there a better way to format this to make it simpler.
I know we cannot use the switch case for this, but just check if there is another way to make it less messy
$scope.$watchGroup(['$scope.EndDateFrom', '$scope.EndDateTo'], function () {
if (!angular.isUndefined($scope.EndDateFrom) && !angular.isUndefined($scope.EndDateTo)) {
return console.log(('expr://' + $filter('date')(new Date($scope.EndDateFrom), 'MM/dd/yyyy') + ' and ' + $filter('date')(new Date($scope.EndDateTo), 'MM/dd/yyyy')));
// $scope.Test1 = 'expr://' + $filter('date')(new Date(disbursementsScheduleVm.processEndDateFrom), 'MM/dd/yyyy') + ' and ' + $filter('date')(new Date(disbursementsScheduleVm.processEndDateTo), 'MM/dd/yyyy');
}
else if(!angular.isUndefined($scope.EndDateFrom))
{
return console.log(('expr://' + $filter('date')(new Date($scope.EndDateFrom), 'MM/dd/yyyy')));
}
else if (!angular.isUndefined($scope.EndDateTo))
{
return console.log(('expr://' + $filter('date')(new Date($scope.EndDateTo), 'MM/dd/yyyy')));
}
});
+3
source to share
No one has answered this question yet
Check out similar questions: