如何在Laravel Blade中实现AngularJS应用 [英] How to implement AngularJS app in Laravel Blade

查看:70
本文介绍了如何在Laravel Blade中实现AngularJS应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实施以下操作: https://github.com/pshevtsov/flashcards 进入我的Laravel Blade看法.我尝试安装angular并链接刀片文件中的所有文件.但这不起作用,因为laravel和angular在文件中使用{{ }}.

解决方案

您可以设置自定义AngularJS花括号以防止与Blade模板引擎冲突:

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('%>');
  });

我建议使用<%= %>,因为它是常用的结构,您可以在下划线模板中找到它. /p>

之后,Angular代码将如下所示:

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

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.

解决方案

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>

这篇关于如何在Laravel Blade中实现AngularJS应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆