Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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);
share|improve this question

2 Answers 2

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.

share|improve this answer
    
Hmm, still doesn't have the javascript execute. –  Tim Aug 6 '13 at 17:09
up vote 0 down vote accepted

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.