I came across the problem of sending JavaScript variables from my backend, in this case an Express.js server, to my frontend, means an AngularJS controller. I'm using Jade as my template engine but the presented solutions should work with others, too.
Basically you've got three options for doing this:
* Put the variable into the view file inside a script tag
* Make an HTTP request from AngularJS and serve the data as JSON from the backend
* Be smart and use ng-init
At the end of the article you find a link to a GitHub repo containing working examples for all the presented solutions. To play with the code fork and modify it according to your needs or start from scratch and add code while reading on. So, let's start...
Your new post is loading...