4

Is it possible at all?

I need to process some backend data, but instead of serving html page with results, I need to output it as json, for one url. How to prepare component to do that?

So the app serves standard html pages now. All of the components process some backend data first, and then use it to display results in html.

But I have one case where I need to output json, for further processing in another, external application. So json component will get data from the backend, just as others, and process it somehow. But how to output that processed data as json, with Content-Type: application/json http header?

5
  • you wan't to generate a json file with angular? for a user or an api? Commented Mar 16, 2018 at 11:59
  • are you getting data from backend in <html> format or you want to prepare JSON file with angular Commented Mar 16, 2018 at 12:05
  • @fab For api, just one component, all others are standard angular components Commented Mar 16, 2018 at 12:05
  • 1
    angular is for the frontend, I suggest you to make that in the backend; you have to execute javaScript to use angular, you can't simple call a url and get the json that is made with angular Commented Mar 16, 2018 at 12:06
  • 2
    So you want to get some data from the server, turn it into JSON, and then output it somewhere? Since when you're using Angular you're in a browser, you can't just save it to disk. You'd have to send it back to the server in another request. It would be better to just do the whole task on the server. Why do you want to use Angular for data processing? it's a GUI framework. Commented Mar 16, 2018 at 12:12

1 Answer 1

2

No.

Angular starts after browser loads all the libraries. If something else than browser access the angular app, all it will get is app/index.html page from src directory. So there is no way it can create json with application/json http header. Because first browser gets the headers, then angular starts.

I go to the backend indeed.

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

Comments

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.