0

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 = {};
    });
ThePearl
  • 151
  • 2
  • 14

1 Answers1

1

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.

rmlan
  • 4,387
  • 2
  • 21
  • 28
Scott
  • 1,690
  • 3
  • 13
  • 18
  • you have to do something like this http://stackoverflow.com/questions/19254029/angularjs-http-post-does-not-send-data to pass the data to serverside though – ThePearl Mar 17 '15 at 01:16