Sunday, 15 June 2014

how to call grails controller from an angularjs function -


I have a grails app and I am trying to use angular for front-end work.

Suppose I have a button on my page, say, 'Add Request' on the click of this button, I call an angular function. But I can not understand how inside the function of this angle, how do I call a 'Grails controller' and method inside the Grails Controller.

  // add data $ scope.addRequest = (Function addRequest () {console.log ('$ scope.request' + $ scope.request); var requestInfo = New string ($ scope .request); requestInfo. $ Save (); $ scope.request = {};});  

There are a few different ways to do this. You can either submit the form, or you can make an Ajax request. I have used both methods, so it depends on how your entire application structure is setup.

AJX

  // Assume that you have different types of elements which $ scope.form = {}; Eg eg & Lt; Input ng-model = "form.something" & gt; Var promise = return $ http.post ("/ controller / action", $ scope.form). Success (work (data) {}) Error (function (data) {});  

form SUBMIT

  jQuery ('# formid'). Submit (); // Just use Jquery to submit the form  

You can also enter a type of INPUT button, submit and include the action in your controller and tag.


No comments:

Post a Comment