user2538755
user2538755

Reputation: 314

Error: [$parse:lexerr] http://errors.angularjs.org/1.2.21/$parse/lexerr?p0=Unterminated

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?

Upvotes: 0

Views: 1118

Answers (1)

Peter Ashwell
Peter Ashwell

Reputation: 4302

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

Upvotes: 1

Related Questions