2

I have this template tags in my html code

{{ djangoVar}}   //Django template tag
{$ angularVar $} //AngularJS template tag

How can I assign {{ djangoVar}} to {$ angularVar $} in my html?

Something like:

{% {$ angularVar $} = djangoVar %}
1
  • {$ angularVar = {{ djangoVar }} $} maybe?! Commented Feb 23, 2015 at 15:32

1 Answer 1

2

The angularVar must be assigned with javascript code. So, in your django template you can do something like

<script>
var django_variables = {};
django_variables.djangoVar = {{ djangoVar }};
</script>

So you declare a django_variables global variable. Then, in your angular controllers you can do:

function MyController($scope) {
    $scope.angularVar = django_variables.djangoVar;
}

The important thing is to run the 1st snippet inside a normal django html template that the context will be passed and {{ djangoVar }} will get its value.

Sign up to request clarification or add additional context in comments.

2 Comments

any other method, this method seems dirty.
There's no other way! You'll end up doing something like what I propose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.