Ad

Combine Angular And Blade Expressions

- 1 answer

I'm using Laravel and Angular together and I was wondering if it's possible and how can I combine both Laravel and Angular expressions?

For example if I have a route that has a parameter that I need from a angular variable:

data-ng-click="myFunction({{ URL::route("myRoute", [<% myObj.id %>]); }})"

Where <% %> are my changed angular open/close expression tags and {{}} blades open/close expression tags.

Ad

Answer

It won't work.

Blade code(php) is run server-side and angular(js) is run on client side. Meaning blade code is always executed before angular code while your code requires blade to execute after angular.

If you were to change your expression so blade is required to run before angular, then it could work.

But, you will soon end up with lots of spaghetti code that way. Blade and angular are very different technologies. Do not intermix them unless it is extremely necessary. And even then make sure to comment your reasons .

Ad
source: stackoverflow.com
Ad