Reputation: 3383
I want to pass a Jade model variable as a parameter to a JavaScript function.
I'm reading the socketUrl
variable from config and passing it to the view:
app.get("/", function (req, res) {
var socketUrl = config.get("socketUrl");
res.render("index", {title: "Ticker", socketUrl: socketUrl});
});
Now I wont to use it in a view script ticker.initialize(socketUrl)
:
html
head
script(src="js/socket.io-1.4.5.js")
script(src="js/ticker.js")
script.
document.addEventListener("DOMContentLoaded", function () {
ticker.initialize(socketUrl);
});
The browser cannot read socketUrl
in that way. How to pass it correctly?
Upvotes: 1
Views: 282
Reputation: 14590
This should work but only with strings:
script.
document.addEventListener("DOMContentLoaded", function () {
ticker.initialize("#{socketUrl}");
});
If it's an object try !{socketUrl}
Upvotes: 1