Question

So I've been trying to figure this out all day and maybe I'm just overlooking something really simple. Here's my problem: I have a nice Nodejs/AngularJS app setup that's using Jade for templating. I do some stuff on the server and eventually get some values back that are rendered in the Jade template by Angular. I have some javascript that needs to run in that view which requires those values that get passed in. However when I test it, that javascript is never run (and even if it did run I'm not sure if those values I passed in would be available to my inline javascript!)

Here's a little example of what I'm trying to do (the Jade partial):

script.
    //Passed in from server
    var thing = {{data.thing}}; 
    var anotherThing = {{data.anotherThing}};

    function doSomething(a, b) {};

    doSomething(thing, anotherThing);
Was it helpful?

Solution 2

So I think I can do what I want to do with AngularJS Directives.

However, the reason why the javascript wasn't executing was because AngularJS (based on jqlite) doesn't see the < script> tags as special - so the solution is to just include the full version of jQuery before AngularJS (source).

OTHER TIPS

Im not entirely sure but I think you should try the following:

script.
    //Passed in from server
    var thing = "#{data.thing}"; 
    var anotherThing = "#{data.anotherThing}";

    function doSomething(a, b) {};

    doSomething(thing, anotherThing);

This isn't getting clear on the new jade page. They had an old doku on their github page which was more specific (you can find it here on webarchive, although that is quite ugly).

Hope that helps!

EDIT: HERE is the old version on github. This one covers far more stuff.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top