使用 Laravel 5 与 AngularJS 刀片标签冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28548694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:57:05  来源:igfitidea点击:

Using Laravel 5 with AngularJS blade tag conflict

phpangularjslaravelbladelaravel-5

提问by imperium2335

I am trying to setup Angular with Laravel 5.

我正在尝试使用 Laravel 5 设置 Angular。

I have tried doing in appServiceProvider:

我试过在 appServiceProvider 中做:

public function boot()
{
    \Blade::setRawTags("[[", "]]");
    \Blade::setContentTags('<%', '%>'); // for variables and all things Blade
    \Blade::setEscapedContentTags('<%%', '%%>'); // for escaped data
}

With:

和:

<div>
  <input type="text" ng-model="yourName" placeholder="Enter a name here">
  <h1>Hello, {{ yourName }}!</h1>
</div>

But I'm getting:

但我得到:

Use of undefined constant yourName - assumed 'yourName'...

采纳答案by lukasgeiter

When doing changes that have to do with Blade (Extending Blade, changing the tags etc) always make sure to delete the cached views.

在进行与 Blade 相关的更改(扩展 Blade、更改标签等)时,请务必删除缓存的视图。

They're located in storage/framework/views.

他们位于storage/framework/views.

Just delete all files (except the .gitignore)

只需删除所有文件(除了.gitignore

If you want something a bit more practical you can create a command to do that. Like this one

如果你想要更实用的东西,你可以创建一个命令来做到这一点。像这个

回答by Paul A.T. Wilson

The easiest way to do this is to simply use @ in front of your Angular code:

最简单的方法是在 Angular 代码前简单地使用 @ :

 <div>
  <input type="text" ng-model="yourName" placeholder="Enter a name here">
  <h1>Hello, @{{ yourName }}!</h1>
</div>

source

来源

回答by Scott Byers

Laravel >= 5.3

Laravel >= 5.3

While adding @ in front of the braces does still work, Laravel has also included another handy blade utility that lets you mark an entire block as-is:

虽然在大括号前添加 @ 仍然有效,但 Laravel 还包含另一个方便的刀片实用程序,可让您按原样标记整个块:

@verbatim
<div>
    {{ ctl.variable1 }}
    {{ ctl.variable2 }}
</div>
@endverbatim

Particularly helpful if you're not doing much with the Blade template rendering

如果您不怎么使用 Blade 模板渲染,则特别有用

回答by Uttam Panara

Else you modify angular syntax...

否则你修改角度语法......

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