3

I need implement this: https://github.com/pshevtsov/flashcards into my Laravel Blade View. I tried to install angular and link all files in blade file. but it doesn't work, because laravel and angular use {{ }} in files.

6 Answers 6

7

In Laravel 5 you can tell Blade to ignore curly braces by doing

@{{ $name }}
Sign up to request clarification or add additional context in comments.

Comments

5

You can set custom AngularJS curly braces to prevent conflict with Blade template engine:

var app = angular.module('app', []) 

  .config(function($interpolateProvider) {
    // To prevent the conflict of `{{` and `}}` symbols
    // between Blade template engine and AngularJS templating we need
    // to use different symbols for AngularJS.

    $interpolateProvider.startSymbol('<%=');
    $interpolateProvider.endSymbol('%>');
  });

I suggest to use <%= %> because it's the often used construction, you can find it in Underscore templates.

After that Angular code will look like this:

<li ng-repeat="phone in phones">
    <p><%= phone.name %></p>
</li>

Comments

1

As of Jan 2016 one needs to do only this:

  • download app.js from Angular homepage.

  • find

function $InterpolateProvider() { var startSymbol = '{{'; var endSymbol = '}}';

and chenge them into whatever, I guess an unofficial practice is <% %> function $InterpolateProvider() { var startSymbol = '<%'; var endSymbol = '%>';

The credit should go to https://scotch.io/quick-tips/quick-tip-using-laravel-blade-with-angularjs

Comments

1

In blade template I code like this:

<div ng-repeat="item in items" class="item" ng-cloak><?='{{item.name}}'?></div>

Comments

1

Laravel 5.3 version introduced a new command to mark the block “as-is”, without parsing:

@verbatim
        Hello, {{ name }}.
@endverbatim

Comments

0

Copy and paste from https://www.trioangle.com/blog/how-to-use-angularjs-in-laravel-blade/

Method 1: Change AngularJS Tags

var sampleApp = angular.module(‘app’, [], function($interpolateProvider) {
  $interpolateProvider.startSymbol(‘<%’);
  $interpolateProvider.endSymbol(‘%>’);
});

Now Laravel will use the {{ variableName }} and Angular will use <% variableName %>. Just like that, you can use Laravel Blade and Angular. You can also change this to anything your heart desires.

Method 2: Change Laravel Tags

Blade::setContentTags(‘<%’, ‘%>’); // for variables and all things Blade
Blade::setEscapedContentTags(‘<%%’, ‘%%>’); // for escaped data

Variables will be: <% $variable %>. Comments will be: <%– $variable –%>. Escaped data will look like: <%% $variable %%>. You can also change this to anything your heart desires.

Method 3: Without changing any Tags

@{{ variableName }}

Now Laravel will use the {{ variableName }} and Angular will use @{{ variableName }}.

I’ve explained you all the methods of AngularJS usage in Laravel Blade and You are recommended to use Method 3.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.