AngularJS with Symphony2

 + 

AngularJS is great. I personally think it is an upgrade from jQuery.

I have been testing AngularJS with Symfony2. One of the problems to build a web application with these two frameworks is that Symfony2’s twig language uses the same symbol operator.

For example: PHP uses , AngularJS uses {{ }}, and Symfony2’s twig uses {{ }} as well.

The solution is to change the default AngularJS symbol to something else.

After your page finish loading the AngularJS, in your script, add the following function:

angular.module(‘apps’, [])
.config([‘$interpolateProvider’, function ($interpolateProvider) {
    $interpolateProvider.startSymbol(‘[[‘);
    $interpolateProvider.endSymbol(‘]]’);
    }]);

It change the symbol operator from using {{ }} to using [[ ]]. 

Remember, you also need to define your app in your html code inside the . In this case, I define the AngularJS app to use apps, therefore, in my , I need to define it using

Have fun coding!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.