Refactoring frontend to directive/service