Reputation:
My question can be stupid still I want help, as I am totally new to Angular2 specially. I have hero-list.component.html file:
<h1>Tour of Heroes ({{mode}})</h1>
<h3>Heroes:</h3>
<ul>
<li *ngFor="let hero of heroes">{{hero.name}}</li>
</ul>
<label>New hero name: <input #newHeroName /></label>
<button (click)="addHero(newHeroName.value); newHeroName.value=''">Add Hero</button>
<p class="error" *ngIf="errorMessage">{{errorMessage}}</p>
<tr *ngFor="let hero of heroes; let i = index">
<td>{{newHeroName.value}}</td>
<td>{{i}}</td>
<td>{{hero.name}}</td>
</tr>
And I want to pass the heroes array to backend i.e. to my controller class in my spring boot application which will insert this data in mysql.
How can i achieve this ? I followed many tutorials and I got a lot more confused.
P.S: I want to achieve this in Angular2 Any help appreciated, Thanks in advance.
Upvotes: 1
Views: 156
Reputation: 84
You can use two ways. One is with spring-cors and another is 'decoupled application' way. CORS is suitable if you want to use cloud based solution. (Ok, I know u are beginner). If you want to use cors, please check the following github project.
https://github.com/borysn/spring-boot-angular2
Just don't panic, that's really easy, just go through and try to understand how that is being done. Another way, is decoupled way. In the following url u can find the solution.
https://blog.jdriven.com/2016/12/angular2-spring-boot-getting-started/
Your question answer is little bit big, that's why I have used website link. Hope that will help.
Upvotes: 1