V
V
Vadim2015-08-18 19:07:28
JavaScript
Vadim, 2015-08-18 19:07:28

How to render a directive in a controller?

For example, there is a directive

(function() {
    angular.module("myDir", []).directive("myDir", myDir);

    function myDir() {
        return {
            restrict: "EA",
            templateUrl: "app/components/myDir/myDir.template.html",
        };
    }
}());

and in the controller i am trying to do the following
var temp = "<div myDir></div>";
var content = $compile(temp)({});

compile simply returns the div element, but would like a template directive.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2015-08-18
@lega

Perhaps the template has not loaded yet, try to check the result in a couple of seconds.

N
Nicholas, 2015-09-02
@healqq

Quote from the angular js docs:
In your case, you need to change the code to:
var temp = "<div my-dir></div>";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question