Reputation: 151
i have a grails app and i am trying to use angular for the front end work.
suppose i have a button on my page, say, 'Add Request'. on click of this button, i call an angular function. but i am not able to figure out, inside this angular function, how do i call a 'Grails controller' and method inside this grails controller.
// add Request data
$scope.addRequest = (function addRequest() {
console.log('$scope.request ' +$scope.request);
var requestInfo = new String($scope.request);
requestInfo.$save();
$scope.request = {};
});
Upvotes: 0
Views: 1069
Reputation: 1690
There are a few different ways to do this. You can either submit the form, or you can perform an Ajax request. I have used both methods so it depends on how your overall application structure is setup.
AJAX
// assuming you have your various form elements bound to $scope.form = {};
// e.g. <input ng-model="form.something">
var promise = return $http.post("/controller/action",$scope.form).
success(function(data) {
}).error(function(data) {
});
FORM SUBMIT
jQuery('#formid').submit(); // Using Jquery to simply submit the form
You can also just put an INPUT button of type SUBMIT And include your controller and action in the tag.
Upvotes: 1