0

I am trying to pull data from my database to display into a form, but I keep getting this error Error: [$parse:lexerr] http://errors.angularjs.org/1.2.21/$parse/lexerr?p0=Unterminated%20quote&p1=s%2055-56%20%5B'%5D&p2=report.incidentTime%20%3D'Couple'sNaNispute%20at%20Robinson%20Hall'. I'm using laravel and angularjs (hybrid approach) in this web app.


HTML

<div class="col-xs-4 col-sm-4 col-md-4">
    <div class="form-group" data-ng-class="{'has-error': documentIncident.reportTitle.$invalid && documentIncident.reportTitle.$dirty}">
        <label for="incidentTime">Report Title</label>
        <input type="text" name="reportTitle" ng-model="report.reportTitle" ng-init=" report.incidentTime ='{{$reports[0]->reportTitle}}'" autocomplete="off" ng-minlength="6" class="form-control input-sm" required>
     </div>
</div>

DB data

enter image description here

The problem I am having is that the apostrophe is preventing the data from being shown. Is there a way to get around this, whether through filtering, escaping or any other approach?

1
  • 1
    Do not pass the $reports from view::make(). Make a service & pull the $reports by a angular service as json, then use like this: reports[0].reportTitle Commented Jan 18, 2015 at 5:12

1 Answer 1

1

The issue is that after laravel is done rendering into your template it looks like this:

ng-init="report.incidentTime ='Couple's dispute at Robinson Hall'"

Which causes the exception because of the unmatched ' in Couple's. What you need to do is

  1. load the data through an API rather than rendering it directly into the HTML (recommended heavily)
  2. use a string escaping function in laravel to make sure the rendered string has a \ before the ' e.g. these question answers
Sign up to request clarification or add additional context in comments.

3 Comments

the {{ and }}s are used in Laravel's Blade templating engine (laravel.com/docs/4.2/templates#blade-templating). That's why the -> is inside there as well. I don't think the OP realizes this approach is flawed because the {{ and }} will never make it past the server side.
Thanks, that was weird. Updated my answer
Plus one on the approach! Separating the UI from the data is definitely the way to go, in my opinion. There is a way to use different opening and closing tags in blade -- namely: Blade::setContentTags

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.