First of all, you need to understand that routeProviders is there to change routes, insider applications, and not transfer data to the server. use a service or factory to transfer data to the server and open the response page. here is a simple example
The form: -
<form name="empForm" ng-controller="insertEmpCtrl" ng-submit="insertEmp()">
name: <input type="text" class="form-control" name="lname" ng-model="formData.lname"/>
<input type="submit" value="Save" />
Routing: -
myApp.config(function($routeProvider){
$routeProvider
.when('/',{
templateUrl : '/your/project/root.html',
controller : 'controler1'
})
.when('/page',{
templateUrl : '/your/project/page.html',
controller : 'controler2'
});
});
factory: -
myApp.factory('factoryname', function(){
return{
insertData: function($scope,$http){
var json_data = JSON.stringify($scope.formData);
$http.post(url, json_data, {
withCredentials: true,
headers: {'Content-Type': 'application/json'},
transformRequest: angular.identity
}).success(function(){
console.log("done");
}).error(function(){
console.log("error");
});
}
}
});
controller: -
myApp.controller('controller1',['$scope','$http','$rootScope','factoryname',function($scope,$http,$rootScope,factoryname){
$scope.insertEmp = function(){
$scope.formFactory = factoryname.insertData($scope,$http);
};
}]);
spring controller: -
@RequestMapping(value="/aurlPattern",method = RequestMethod.POST)
public String insertmethod(@RequestBody FormModelObject FormModelObject) {
return "responsePage";
}