How to use Angular JS and Laravel 4 without conflict with the blade?

6

I would like to know how do I configure Laravel 4 to use AngularJs without conflict with the Blade, since the interpolation tags are the same?

    
asked by anonymous 17.02.2016 / 12:04

1 answer

6

For you to not conflict, you will have to change the internal processing tags of BladeCompiler of Laravel. Or, depending on the case, you can actually change the AngularJS .

LARAVEL BLADE

You can do this by using the facade class for BladeCompiler , called Blade (which is an alias, you can check in app.php ).

In the app/start/global.php file for your application, do the following code inclusion

Blade::setContentTags('[[', ']]');

Blade::setEscapedContentTags('[[[', ']]]');

Note : It is worth remembering that Blade has compiled views cache (according to the modification date of your view blade). So what has been compiled before then needs to be reprocessed, so you do not get the data before changing the Blade's opening and closing tags.

In Laravel 5, you can use the php artisan view:clear command to clear the views that were compiled in the old tween.

ANGULAR JS

If it is laborious or you do not want to change the BladeCompiler syntax, you can change the interpolation tags of AngularJS . You can use the following method:

var myApp = angular.module('myApp', [], function($interpolateProvider) {
    $interpolateProvider.startSymbol('[[');
    $interpolateProvider.endSymbol(']]');
});

Update

It is possible in Laravel to escape the interpretation tags {{ }} using the at sign ( @ ). So, since the angular interprets these keys in the DOM, then you could do this:

 {{ $codigo_laravel }}

 @{{ codigo.angular }}

Another example:

<input type="name" data-id="@{{ user.id }}" />
    
17.02.2016 / 12:16