Display all categories as plain text

This is a general solution for all taxonomies. To be used inside the loop (else replace get_the_ID() with post ID ):

$taxonomy = 'category';
$terms = get_the_terms( get_the_ID(), $taxonomy );
if( $terms ){
   $term_slugs = array_map('esc_attr',wp_list_pluck( $terms, 'slug'));
   $class = implode(' ', $term_slugs);
}else{
   $class="no-term";
}