html
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f1f1f1;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
<meta charset="UTF-8">
<title>ziom</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="people">
<table>
<tr>
<th>id</th>
<th>imie</th>
<th>nazwisko</th>
<th>pensja</th>
</tr>
<tr ng-repeat="x in names">
<td>{{ x.id}}</td>
<td>{{ x.firstName }}</td>
<td>{{ x.lastName}}</td>
<td>{{ x.salary}}</td>
</tr>
</table>
<p>addresy zamieszkania</p>
<table>
<tr>
<th>id</th>
<th>miasto</th>
<th>kod pocztowy</th>
<th>ulica</th>
<th>numer domu</th>
</tr>
<tr ng-repeat="x in names">
<td>{{x.id}}</td>
<td>{{x.address.locality}}</td>
<td>{{x.address.zipCode}}</td>
<td>{{x.address.street}}</td>
<td>{{x.address.streetNumber}}</td>
</tr>
</table>
<table>
<tr>
<th>id</th>
<th>phone</th>
</tr>
<tr ng-repeat="x in names">
<td>{{x.id}}</td>
<td>{{x.phones }}</td>
</tr>
</table>
<div ng-controller="registerController">
<form action="javascript:void(0);">
<h2>Register Form</h2>
<div>
<label>Name</label>
<input type="text" ng-model="firstName" placeholder="firstName" required="required" firstName="firstName"
style='margin-left: 10px;'>
</div>
<div>
<label>lastName</label>
<input type="text" ng-model="lastName" placeholder="lastName" required="required" lastName="lastName"
style='margin-left: 10px;'>
</div>
<div>
<label>Salary</label>
<input type="text" ng-model="salary" placeholder="salary">
</div>
<div>
<label>Address</label>
<input type="text" ng-model="address" placeholder="address"
>
</div>
<div>
<label>Address</label>
<input type="text" ng-model="locality" placeholder="address" required="required" locality="locality"
style='margin-left: 10px;'>
</div>
<button ng-click='Register()' style='margin-top:15px'>Register</button>
</form>
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('registerController', function($scope, $http) {
$scope.Register = function() {
$http.post("http://localhost:8080/employee/add",{'firstName': $scope.firstName,'lastName':
$scope.lastName,'salary': $scope.salary, 'address': $scope.address.id})
.success(function(response) {$scope.usersData = response;$scope.message = response.message;})
$http.post("http://localhost:8080/address/add",{'locality': $scope.locality,'street':
$scope.street})
.success(function(response) {$scope.usersData = response;$scope.message = response.message;}
);
};
});
</script>
<script>
var app = angular.module('myApp');
app.controller('people', function ($scope, $http) {
$http.get('http://localhost:8080/employee/employee')
.success(function (response) {
$scope.names = response;
});
});
</script>
</body>
</html>
w Postmanie tak dodaje nowego Employeer'a z addresem
{
"salary": 3443434,
"firstName":"Jan",
"lastName":"343434",
"address": {
"id":1
}
}
Ale nie wiem jak to zrobic w htttp post Angular pomoże ktoś?