How to implement AngularJS app in Laravel Blade

烂漫一生 提交于 2019-12-01 09:03:06

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>

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

@{{ $name }}

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

In blade template I code like this:

<div ng-repeat="item in items" class="item" ng-cloak><?='{{item.name}}'?></div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!