Refactored pattern into angular directive.