Answer the question
In order to leave comments, you need to log in
How to give json and render the page in one request?
I am making a nodejs+mongo+angular project. For one request router.get('/') I want to render a page and return json with data from mongo.
Those need to work res.json (users) and res.render ('index') at the same time + users ended up in the angular scope.
Is it possible?
Answer the question
In order to leave comments, you need to log in
Well, give the rendered data in json, but you obviously won’t be able to send two different bodies with one request ... Or, again, you will have to resolve it on the client, and in the response mark ContentType as your application/json+html and resolve it in global interceptors . I just don’t understand why you need to “pre-render” something for the angular application. Let it render on the client or do you think it will be much slower? If you already have performance problems and a prerender can help you, then you can optimize the bindings (if you have angular 1.3 of course). In a word, I doubt that this is the weak point. Again, you can try to render on the client through ReactJS with its virtual DOM, although this will not give much benefit with optimized bindings.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question