0

Usually Angular get from HTTP request the JSON from server side (like Django). But, to accelerate rendering, would like to write down on server side the JSON into a Javascript VAR and let proceed Angular on this javascript variable containing the JSON.

My question are: 1) How to pass this javascript var to angular $scope variable ? (without HTTP).

2) Is writing down the JSON into the HTML a bad/good practice ? (given my web app is fairly static).

3

1 Answer 1

0

You can do a simple $scope = {{ some_django_tag|safe }}. I can't see why it would be a bad practice if you're 100% sure that the output will be valid JS. I actually do this a bit to instantiate the scope on the page load.

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

Comments

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.