0

I have a symfony2 application also supporting REST. I would like to hear if it would be a good idea to go over the learning curve of angularjs or stick with jQuery and twig. It seems like twig already has some nice features similar to those in angularjs such as filters and stuff. Also if l use angular it will break symfon's MVC since I will most probably have less views . On the other hand I like the responsiveness of angular and it's like the new trend. Can you list some pros and cons in using angular in this scope?

Update Thank you all for the detailed answers but I'm still missing the part where you say angularjs is not braking the server-side MVC. In a typical back-end MVC we have a bottom-up approach where the controller is communicating with the model to prepare the data to pass to the view. So my PostController will pass a list of Pot objects to the view and using twig I can nicely iterate over them and print their properties. On a typical angular application though, its the other way around. We have a top-down approach where the View starts with nothing and later communicates with the controller to get the data needed (typically in JSON format) to render different parts of the page.

4 Answers 4

8
  • Twig is server-side, while AngularJS is client-side. You can't really compare it
  • AngularJS is not breaking Symfony's MVC. Symfony just serves another purpose: instead of providing a complete app, it only provides an API which can be used by angular.js
  • If you want to use AngularJS because it's a new trend, don't do it. It makes no sense to follow a trend if you don't need it.
  • AngularJS works pretty well with Symfony.

In the end, it completely comes down to the project. One project would benefit from using AngularJS, another will only make things more difficult.

Sign up to request clarification or add additional context in comments.

Comments

4

I have a symfony2 application also supporting REST.

I'll assume you mean you have created RESTful data-driven api in Symfony that uses xml/json or some other data-centric non-html format? If not than I'm confused by this introduction since all websites overlap with REST in a generic way.

I would like to hear if it would be a good idea to go over the learning curve of angularjs or stick with jQuery and twig.

By far the simplest approach (if you are already familiar with Symfony) is to leverage Twig to render your views and pepper it with jQuery for the client-side dynamic/async rendering. Angular adds more conceptual layers than Twig. For instance it duplicates model management in the client. Twig has very low impedance for mapping views to models whereas Angular views will require much more code to manage this mapping. In some cases this decoupling views from data can be a huge boon, if architected correctly. It depends on the needs of your team.

My recommendation would be to implement a small slice of your functionality in both Twig and Angular and keep in mind they have dramatically different runtime considerations and real world mechanics. The most important difference is that Angular ships as client-side only rendering and Twig ships as server-side only rendering. These are fundamentally different concepts. It should be noted there is no reason you can't pre-render Angular on on the server or have the browser render using Twig. These are advanced and non-standard approaches that aren't currently native features of either Twig or Angular, but are entirely possible as optimization steps.

The "snappiness" you attribute to Angular is largely an arbitrary function of specific html + css complexity in a given context and the magnitude of difference between state changes. Wether you put the primary burden of view rendering on the server or client you can properly optimize that solution to be unobtrusive to your user. The issue is which side of the equation do you want to put your optimization efforts?

It seems like twig already has some nice features similar to those in angularjs such as filters and stuff. Also if l use angular it will break symfony's MVC since I will most probably have less views.

In general the design of Angular and Symfony are incongruent by analogy with the exception of the semantics of their view rendering, which may be misleading you. The best way to decide which is better for you and your team is to try them both.

You are not breaking Symfony's MVC in the slightest by using Angular. In essence a view is just a representation of data according to a format so whether your server sends JSON data to Angular or having Twig render HTML on the server you're still doing the "V" of Symfony's approach to MVC.

On the other hand I like the responsiveness of angular and it's like the new trend. Can you list some pros and cons in using angular in this scope?

If your user interface is very document/hypertext driven (in other words transparency for search engines matters to you) and you use less than a dozen async calls sitewide you'll almost certainly tend towards twig + jquery.

If your user interfaces require a level of complexity approaching a "desktop" application you'll almost certainly tend towards angular.

Many applications appearing on the market live between the two scenarios outlined. The closer you get to one the more clear your decision will become.

The one thing I can say is that if you have any doubt than you'll probably want to stick with twig/jquery, simply because they are very well understood and proven techniques and require a lot less of a learning curve if you're already building with Symfony.

Comments

0

AngularJS is a full MVC WebApplication Framework, while jQuery is more to add javascript functionality to particular parts of your website, with less code amount...

Angular is a great solution, but a bit more to learn, while jQuery is a bit less to learn...

It will depend on your skills and what kind of website you want to do...

For big WebApp I would suggest Angular, for just some JS enhencements use jQuery

Comments

0

For me TWIG and TWIG only with js/jQuery/Ajax/Json. Nothing more is needed, really. I don't see any pros of joining Angular with Symfony, while symfony provides everything that is mandatory. Twig is actually HTML on steroids with {{ data }} and {% functions %} that are marvelous and simple, when You prepare data from controller properly. Next thing that works great with this is CSS grid. No bootstrap or any frameworks needed to well organize things in proper way.

But! You or Your team must have skill to prepare good controllers, to not overheat the view. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.