Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dhiman252's avatar

Blade and angular mixing

In Laravel we can escape {{}} by prefixing the first curly brace with an @ symbol. @{{ $variable }} will return {{ $variable }} and AngularJS can deal with that.

Now, I have an image tag in the blade like the following:

<div ng-repeat="ratingImage in user.ratingImages track by $index"><img src="@{{ ratingImage }}"/></div>

and when I run this I get the following errors in my firebug console:

`"NetworkError: 404 Not Found - http://xwz.me/home/%7B%7B%20user.image%7D%7D" {{ user.image}} 

"NetworkError: 404 Not Found - http://xwz.me/home/%7B%7B%20ratingImage%20%7D%7D"`

How to resolve this ?

0 likes
8 replies
spekkionu's avatar

Is user a blade variable or an angular variable?

If it is a blade variable you will not be able to loop through it with ng-repeat as angular has no idea what it is.
It would be better to populate it with a separate http request using the $http module.

If it is already an angular variable then remove the @ as blade wont know what it is and angular should be the one printing it.

mehany's avatar

Try to change either one syntax to avoid conflict!

// example for blade 
Blade::setContentTags('<%', '%>'); // For variables.
Blade::setEscapedContentTags('<%%', '%%>'); // For escaped data.

or

var customInterpolationApp = angular.module('customInterpolationApp', []);

customInterpolationApp.config(function($interpolateProvider) {
   $interpolateProvider.startSymbol('{['); // or change it to something else
   $interpolateProvider.endSymbol(']}'); // or change it to something else
});

https://docs.angularjs.org/api/ng/provider/$interpolateProvider

dhiman252's avatar

@spekkionu

user is an angular variable and if I tried to remove the @symbol I receive an error that user is undefined.

@ mehany I cannot change it now as the application has been built can you suggest any other way to deal with this ?

willvincent's avatar

Yep, in your blade template, your image should be like this:

<img ng-src="@{{user.image}}" />
2 likes
mehany's avatar

@willvincent the OP is using a for loop

Edit: oh I see, there is another call for the user's image

Please or to participate in this conversation.