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?

user2538755
  • 314
  • 1
  • 6
  • 21
  • 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 – Anindya Dhruba Jan 18 '15 at 05:12

1 Answers1

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
Community
  • 1
  • 1
Peter Ashwell
  • 4,292
  • 2
  • 18
  • 22
  • 1
    the `{{` and `}}`s are used in Laravel's Blade templating engine (http://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. – kstev Jan 18 '15 at 06:34
  • Thanks, that was weird. Updated my answer – Peter Ashwell Jan 18 '15 at 06:39
  • 1
    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` – kstev Jan 18 '15 at 06:44