AngularJS with Symphony2

General

 + 

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!

Next | Previous

Other posts