Using Laravel 5 with AngularJS blade tag conflict

不问归期 提交于 2019-11-30 02:37:46

问题


I am trying to setup Angular with Laravel 5.

I have tried doing in 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'...

回答1:


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

They're located in storage/framework/views.

Just delete all files (except the .gitignore)

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




回答2:


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

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

source




回答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:

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

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




回答4:


Else you modify angular syntax...

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


来源:https://stackoverflow.com/questions/28548694/using-laravel-5-with-angularjs-blade-tag-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!