Using Angular Material in the angular-material-fullstack Yeoman generator, I am incorporating a toast:
var last = {
bottom: false,
top: true,
left: false,
right: true
};
$scope.toastPosition = angular.extend({},last);
function sanitizePosition() {
var current = $scope.toastPosition;
if ( current.bottom && last.top ) current.top = false;
if ( current.top && last.bottom ) current.bottom = false;
if ( current.right && last.left ) current.left = false;
if ( current.left && last.right ) current.right = false;
last = angular.extend({},current);
}
$scope.getToastPosition = function() {
sanitizePosition();
return Object.keys($scope.toastPosition)
.filter(function(pos) { return $scope.toastPosition[pos]; })
.join(' ');
};
var showSimpleToast = function() {
$mdToast.show(
$mdToast.simple()
.content('Please enter a valid stock name.')
.position($scope.getToastPosition())
.hideDelay(3000)
);
};
What could I do to 'get this code out of the way'? Is it worth implementing into a service? I simply don't want it to take up so much room in my controller.