Ad

Laravel {!! Form::open() !!} Doesn't Work Within AngularJS

- 1 answer

I'm using Laravel 5.0 + AngularJS to build some website. The problem is when I use laravel illuminate, things like

{!! Form::open() !!}
{!! Form::close() !!}

are not compiled into forms, instead, the plain texts are displayed.

I guess it's because I'm also using angular, which already have certain use of '{}';

when I use {!! Form::open() !!} in another page with no angular it works normally.

How can I use laravel form inside angular app? (need the features like csrf token)

Ad

Answer

You will either need to change the blade syntax for laravel or change it for AngularJS. I tend to lean on changing it for Lavavel.

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

Add that into a common file, such as routes.php.

Update your references from {!! to <% and !!} to %>.

Edit:

If you would instead like to do this on the AngularJS side, you can with adding this into your app.js file (credits: scotch.io).

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

Replace the module name with your project's app module name.

Ad
source: stackoverflow.com
Ad