A
A
Artem2017-02-07 17:23:26
Java
Artem, 2017-02-07 17:23:26

How does Angular2 and Java work?

I can not understand and find a simple example of how Angular2 and Java work! I generated a jhipster project in Angular2, but I can't figure out how everything works there!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Frozen Coder, 2017-02-07
@frozen_coder

Yes, in theory, Java-non-Java, Angular-non-Angular, the client communicates with the server via REST. The server provides the API, accepts requests from the client, and sends responses back to it. The client uses this API, sends requests and receives responses. You don't necessarily need a bunch of Angular2 and Java, start with a tour of heroes better from the Angular2 docs. Then, on the Java API side, you can do different things, there may be Java EE, Spring, Play, or something else. But the essence is the same - REST.

V
Vorh, 2017-02-07
@Vorh

Here is an example of how to communicate in Angular2 via a REST
GET request to the backend:

getList(): Promise<Data[]> {
    return this.http.get(Ваш url + '/getData')
      .toPromise()
      .then(response => 
      response.json().data as Data[]);
  }

You can read more details here: Angular2 HTTP
Java Spring Controller which processes the request and returns the requested data:
@RequestMapping(name = "/getData")
    public List<Data> getListData(){
        List<Data> list = new ArrayList<>();
        list.add( new Data());
        list.add( new Data());
        list.add( new Data());
        list.add( new Data());
        return list;
    }

If you are going to deal with Spring, then here I posted a list of useful resources for learning

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question