samedi 30 mars 2013

AngularJS Trick : posting data using url form encoded

AngularJS is a great framework : really, i mean it, i havent seen such beauty in client side development for years (say Ng for friends).

It gives you a clean MVC model far superior than Backbone.js for mono page app : most of its extraordinary effectiveness comes from coding by convention pattern.

The AngularJS framework does a lot for you behind the curtain.

But yes, there is always a but somewhere,  sometimes, it does too much (I use Angular 1.0.5 for this post) .

As AngularJS afficionados say, you can use AngularJS without JQuery, it's highly recomanded they say, as JQuery can twist the new thinking you must have when using AngularJS.

I agree with most of it.

But, when dealing with one of the most trivial task in RIA development, Ng is just too opinionated.

Indeed, Ng can do some REST with ease, but it does it his way and it's quite painful when you don't know the trick to do it the way you want.

By default, Ng uses JSON to send your request data.

If your REST service does not deal with such request,  then you're dead : 500 response code you will receive.

What must we do  ?

First import JQuery in your page.

Then, You have to configure the HTTP provider for your module and transform your request data using JQuery param function, ideally in the app.js file :

Loading ....

Now, you can issue a POST request with Ng's elegant way :

Loading ....

I think it's really bad to have to use JQuery for such trivial task.

Many Ng users have complained about it, and i hope the Ng Team will fix it.

Still, AngularJS is great, long life to AngularJS !

Contrat Creative Commons
the jee architect cookbook by Olivier SCHMITT est mis à disposition selon les termes de la licence Creative Commons Paternité - Pas d'Utilisation Commerciale - Pas de Modification 3.0 Unported.

Aucun commentaire:

Enregistrer un commentaire