When it comes to Ajax, it looks like Symfony (v. 2.7) and AngularJS (v. 1.4) don't go well together ;-)
I see two ways to make them cooperate - my question is: Which one is better?
- Adapt AngularJS to be compatible with Symfony
- Adapt Symfony to be compatible with AngularJS
For 1, this is the best instruction I found: http://harmssite.com/2014/09/mixing-angular-and-symfony/
Advantage: Can use $form->handleRequest($request); in Symfony to get all form fields at once.
Disadvantage: Cannot set default value's for <input>'s, cause AngularJS overwrites them. Solution:
- Set it in Angular's controller (i.e. in
app.js). But if the value comes from the database (i.e. Symfony), how can you get it intoapp.js? Render the entireapp.jsfile through Symfony's templating system? => Looks like overkill to me. - Set it inside the HTML/twig file with
ng-init, as shown here: AngularJS - Value attribute on an input text box is ignored when there is a ng-model used? => This is more a workaround than a solution ;-)
For 2, the major disadvantage is that you need to read each form field separately into Symfony, using $post = $this->getRequest()->getContent(); as shown here:
AngularsJS POST JSON data to Symfony2
I haven't tried this approach, so I don't know if there are further problems down the way ;-)