What is $compile in AngularJS, and when would you use it?

$compile is a service that compiles HTML strings or DOM elements into a template, linking it with a scope. It’s often used in custom directives to add dynamic behavior to elements.

const compiledElement = $compile('<div>{{message}}</div>')($scope);