Maybe move this out into a directive? I'm not sure if this is controller logic.