1

I have the textarea contains the html code and some template jinja2 directives. So as you might guess the javascript crashed on page load, because Angular find some directives from jinja2 inappropriate ( for example {{ variable }} ). I mean these directives might be valid for Angular, but they are not event in a $scope, something like that...

I added recommended Angular directive ngBindTemplate both to textarea and even to div-wrapper, but this doesn't work.

Here is some source code from the browser:

<textarea id="body" name="body" ng-non-bindable="">&lt;!DOCTYPE html&gt;
&lt;html lang="ru"&gt;
&lt;head&gt;
    &lt;meta charset="utf-8" /&gt;

    &lt;link rel="icon" href="/static/images/favicon.ico" type="image/x-icon" /&gt;
    &lt;link rel="shortcut icon" href="/static/images/favicon.ico" type="image/x-icon" /&gt; 

    &lt;title&gt;{% block title %}Title{% endblock %}&lt;/title&gt;


    &lt;link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" /&gt;

    &lt;link rel="stylesheet" href="/static/css/styles.css" type="text/css" media="all" /&gt;
&lt;/head&gt;
&lt;body&gt;
.....
</textarea>

As you can see the html inside textarea is escaped, but seems it make no sense to AngularJS and it compiles the content anyway.

James May
  • 1,371
  • 3
  • 20
  • 37
  • When you use ng-app to load a module onto a portion of the DOM you're basically telling angular to process anything that happens within the descendants of that element. You can change the characters used for angular interpolation if that helps you. – shaunhusain Apr 01 '14 at 22:02
  • I also suggest looking into ng-bind-html ng-bind $sce and ngSanitize since it will probably all apply though it's difficult to grock exactly what you're trying to achieve. Do you want it to just show the HTML as plain text or do you want to use the HTML to be interpreted by the browser? Also really what's the end goal? Why mix two things with templating, why have the backend touch the front-end at all? The service layer should just be RESTful and communicate with JSON so parts can be rebuilt and re-used. – shaunhusain Apr 01 '14 at 22:13
  • I'm building the Administration Interface where I have the ability to edit site templates. Template engine is Jinja2. So I just displaying the textarea with the html + jinja2 code in it for editing. – James May Apr 02 '14 at 08:20
  • If somebody interested, I solved my problem simply by changing AngularJS delimiters. http://stackoverflow.com/questions/12923521/angular-js-custom-delimiter – James May Apr 03 '14 at 16:37

0 Answers0