1

Question: Does this work without e.g. ejs/jade? And where is the difference between a framework like AngularJs and a templating engine?

E.g.

Server.js

var express  = require('express');
var app      = express();

Routes.js

app.get('/', function(req, res) {
    // res.render('index.ejs');
    res.sendfile('index.html', {
        user : "Tom"//req.user
    });
});

Index.html (Here I have no idea how to do this)

<body ng-app="App" id="App" ng-controller="RootCtrl as rootCtrl" ng-mouseleave="rootCtrl.exit()">
    <script> 
      // angular.module('$user', []).constant('$user', <%= user %>)
    </script>
    ....

Tutorials I looked into:

http://www.mircozeiss.com/how-to-pass-javascript-variables-from-a-server-to-angular/ http://www.linkplugapp.com/a/224929

1 Answer 1

1

Yes this should work, but you need to enable ejs in your express app.

app.set('view engine', 'ejs'); 

I did the same thing with laravel and blade.

Sign up to request clarification or add additional context in comments.

2 Comments

Actually I try to avoid using ejs. It seems simple but I have the feeling for every problem I adress in my application I have to use another language or tool. So is there a solution with just plain angular and no ejs. That's the reason why I commented this out.
You cant pass data from the server directly to your html without template engine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.