Hi, In the plnkr I changed `compiled.html()` to `compiled`. It seems that angular is ignoring html and head tags and compiles just the body and returns the output. It is an interesting find! New plnkr:
http://plnkr.co/edit/vNcycL2ycZZtevmaX7qf?p=preview Regards, Vaibhav Gupta On Thursday, 7 April 2016 02:59:23 UTC+5:30, Emil wrote: > > I'm relatively new to AngularJS so I'm still very much in a learning > phase, so please bear with me :-) > > > I've a service which purpose is to get a html template via $http, cache > it and then compile it via $compile with some scope data attached. > > The purpose of this is to create a HTML email template (a string > essentially) which I can send to my backend and send it to a recipient. > > > But I ran into a peculiar (perhaps, it might just be me not being in the > "angular-zone") exception. > > > When my html template consists of html, head and body tags - the $compile > function > doesn't run or doesn't run correctly, I'm getting nothing back. Remember, > this $compile will not be added to the DOM in anyway. > > > But when I do the same thing, with same (scope)data with the same template > just without these HTML defined tags, it works. > Which made me think that I either am using the $compile function wrong or > I am using it to the wrong purpose and perhaps there are better ways to > accomplish what I want. > > > This is my email service: > $http.get('my-html-template.html', { > cache: $templateCache > }).then(function(res){ > var compiled = $compile(res.data)(scope); > $timeout(function() { > console.log(compiled.html()); > }); > }); > > > I've created a plnkr so you can run it > <http://plnkr.co/edit/8moTd2aAu2OzZVX7axeN?p=preview>. > > I could of cause just skip the HTML tags all together and insert them e.g. > in the back-end so it's more out of curiosity that I'm wondering. > > > *note: also posted on SO > <http://stackoverflow.com/questions/36459415/get-html-compile-with-html-and-body-tags>* > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
