0

I am building a web app and I want to know what is the best and the safest way to pass a variable from a django context dictionary to Angular.

I have access to a variable of the context dictionary from Django template. Should I use ng-init to pass that value to an Angular variable?

It is about a user profile page and I want the user to be able to update his Data. The Data is initialized when calling the view but when I want him to update that Data i want to post using an Angular JS variable.

Thanks in advance

1 Answers1

0

I would add the data as the initial value of each form tag. This answer has a useful "initial" directive to do it in a way that would allow you to use the form even without Angular.

<input name="profile[name]" value="Joe" ng-model="profile.name" initial>

With that, Angular would take the initial value fro the value attribute (as it should be), so that your form would have an initial value even without Angular running.

Community
  • 1
  • 1
C14L
  • 12,153
  • 4
  • 39
  • 52