The compile function
In the previous recipes in previous chapters we mentioned the $compile
function using the compile complete recommended syntax, as follows:
compile: function compile(tElement, tAttrs, transclude) { return { pre: function preLink(scope, iElement, iAttrs, controller) { ... }, post: function postLink(scope, iElement, iAttrs, controller) { ... } }
In this recipe, we will show the alternative method of calling and using the $compile
function.
Getting ready
The baseline code for this recipe is the same as in the previous chapter.
How to do it…
As we are using the same code base, and we already wrote the code in the previous recipe, open the dynamic-template-directive.js
and take a look at the linkF
function:
var linkF = function(scope, element, attrs) { element.html(getTemplate(scope.content.type)).show(); $compile(element.contents())(scope); }
How it works…
Note that inside the linkF
, we used the .html()
and .show()
methods from jQuery Lite (built in to AngularJS) to...