I'm using Symfony2 with Twig and AngularJS. I need to pass Twig variable to angular's function. Currently I tried doing that like this: ng-click="submitPost({{ channelName }})"
but when I console.log
to check that variable I see it as undefined. How do I pass Twig variables to angular functions?
Using Twig variable in AngularsJS
1.1k views Asked by Einius At
2
There are 2 answers
0
On
If you are using Twig with AngularJS you will most likly run into conflicts as you might know. One solution is to use Angulars $interpolateProvider
to change the start and end interpolation tags like so:
angular.module('myApp', []).config(function($interpolateProvider){
$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
});
In this case Angular will use {[{
and }]}
to interpolate expressions. It might be a bit odd to type but you can chose whatever you like. However, this will solve the conflicts between Twig and Angular.
Use temporary javascript variable to store the twig variable