How do I get a promise from a compile in AngularJS?

Viewed 1281

There's an event that needs to be triggered after a compilation is finished.

This is what my parent controller looks like:

myApp.directive("ParentDirective", ["$rootScope", "$compile",
    function($rootScope, $compile) {
        return {
            link: function (scope, element) {
                var onClick = function () {
                    if (!scope.childDir) {
                        scope.childDir = $compile('<div ng-controller="childCtrl"/>')(scope);
                        $(scope.element).append(scope.childDir);
                    }
                    $rootScope.$broadcast('event');
                }

                $(element).click(onClick);
            }
        }
    }
]);

And in childCtrl I have an listener:

$rootScope.$on('event', doSomething);

The problem is that the directive processing takes place after my controller triggers the event. Is there a way to get a promise from the compiler or any way to trigger the event after the compilation takes place?

1 Answers
Related