I want to use $compile in a controller inside a function and not in a directive. is it possible? I am trying the below code.
$compile(\'
I tried @Vaibhav Jain's answer, with no success. After a little more digging, this is what I found to work on Angular 1.3, and jQuery:
$(function() {
angular.element(document).injector().invoke(['$compile', function ($compile) {
// Create a scope.
var $scope = angular.element(document.body).scope();
// Specify what it is we'll be compiling.
var to_compile = 'Cancel';
// Compile the tag, retrieving the compiled output.
var $compiled = $compile(to_compile)($scope);
// Ensure the scope and been signalled to digest our data.
$scope.$digest();
// Append the compiled output to the page.
$compiled.appendTo(document.body);
});
});