I'm trying to add some html into a tinyMCE textarea (tinyMCE can show html inside those editable textareas while allowing the user to manipulate them live).
So, lets say my template is:
var template = '<span>hello {{ user.name }}</span>'
I'm trying to:
- compile the template with the current controller's scope.
- stringify it into a varialbe (after it was compiled)
- concat it to the end of the tinyMCE editor.
my controller's code is:
// [...]
var user = {};
user.name = "john";
$scope.user = user;
$templateRequest('<PATH_TO_TEMPLATE>').then(function() {
var linkingFunc = $compile(template);
// if I understand correctly, this should replace the user.name with "john"
var parsedTemplate = linkingFunc($scope);
console.log(parsedTemplate.prop('outerHTML'));
});
// [...]
The output of parsedTemplate.prop('outerHTML') is:
<span>hello {{ user.name }}</span>
Does it get rendered only if I inject it to the DOM after linking it to the scope?
is there a way to get it compiled in the javascript without rendering it back?
I'm trying to get some sort of var templateWITHOUTVariables which will euqal <span>hello john</span>
any ideas?
thanks!
$digestdoesn't mandate injection back into DOM. Those posts are basically pointing in the direction that once you$compileyour HTML string with the current scope, it may not immediately be available to the console.log statement unless you run a$digestcycle or put it inside a '$timeout` like so -$timeout(function() {console.log(parsedTemplate.prop('outerHTML')) });