Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interact between Angular and Java (in terms of passing variables back and forth)?

I'm trying to develop a software tool where people can enter an ID and then that ID will be searched using a third party website in the background and the results of that search will be displayed in a different fashion on my software. However, my front-end is in AngularJS while the back-end code is all in Java. How do I get Angular to pass that data to a function or similar? My coworker said something about passing the value to a controller and having that interact with the java program, but I didn't really understand what he was trying to say.

But for example, to make my question more clear:

Say I have this HTML/Angular code:

<div>
    Name:
    <br />
    <input type="text" ng-model="name"> {{ name }} </input>
    <br />
</div>
<script src="angular.min.js"></script>

and then I have this Java code:

public int letterCount(String name){
    return name.length();
}

How do I pass the variable "name" from the first file to the java method "letterCount" ??

like image 958
Anon Ymous Avatar asked Nov 28 '25 13:11

Anon Ymous


1 Answers

What do you mean by 'while the back-end code is all in Java.'?

is it in the same project? (or) is it part of some rest services?

If your back-end code is developed with REST end points (URLs), then use them in Angular JS to post and get the data. Rest example.

if your back-end java code is part of the same project (MVC), then usually you will have a servlet (controller) URL to which you can send the data to invoke the back end logic. Servlet example.

like image 122
K139 Avatar answered Nov 30 '25 01:11

K139



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!