0

When I try to create an AngularJS ui-grid table with data that contains a '(' and then whitespace before the closing ')' inside a string, then I get an AngularJS error saying:

Syntax Error: Token '32' is unexpected, expecting [)] at column 22 of the expression [entity[''](trimpoint 32h)] starting at [32h].

Here is the complete HTML code that I am trying to use to create the table:

<html> <head>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/3.2.5/ui-grid.css" /> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/3.2.5/ui-grid.min.js"></script>
    <script type="text/javascript">

var app = angular.module('MyGridApp', ['ui.grid']);

app.controller('bodyController', ['$scope', function($scope) {
    $scope.myData = [{'(trimpoint 32h)': "Moroni", age: 50},
                     {'(trimpoint 32h)': "Tiancum", age: 43},
                     {'(trimpoint 32h)': "Jacob", age: 27}];
    $scope.gridOptions = { data : 'myData' }; }]);

    </script> </head> <body ng-app="MyGridApp" ng-controller="bodyController">
    <div ui-grid="gridOptions">
    </div> </body> </html>

If I replace the round brackets with square brackets, then it works fine and the table is rendered i.e:

$scope.myData = [{'[trimpoint 32h]': "Moroni", age: 50},
                 {'[trimpoint 32h]': "Tiancum", age: 43},
                 {'[trimpoint 32h]': "Jacob", age: 27}];

Is there any reason why AngularJS shows an error while trying to parse this data? It seems like a valid JavaScript string to use as an object name. Thanks

12
  • what happens if you use a backslash with your parenthesis ? \( random text \) Commented Nov 18, 2016 at 12:36
  • also, could you too try $scope.gridOptions = { data : $scope.myData }; ? Commented Nov 18, 2016 at 12:37
  • Hi @trichetriche, thanks for your response. Same "parse syntax" error with both suggestions unfortunately. Commented Nov 18, 2016 at 12:43
  • Could you post your full error as a screenshot or in plain text please ? Commented Nov 18, 2016 at 12:45
  • angular.js:10023 Error: [$parse:syntax] errors.angularjs.org/1.2.21/$parse/…) at angular.js:36 at cb.throwError (angular.js:10496) at cb.consume (angular.js:10530) at cb.functionCall (angular.js:10777) at cb.primary (angular.js:10480) at cb.unary (angular.js:10719) at cb.multiplicative (angular.js:10702) at cb.additive (angular.js:10693) at cb.relational (angular.js:10684) at cb.equality (angular.js:10675) Commented Nov 18, 2016 at 12:47

1 Answer 1

0

The answer to the problem is that you need to put a non blank space before each parenthesis.

You can take this one { } or use a unicode character, also try Alt + 255 on Windows, Or you can type Ctrl + Shift + U, keep Ctrl + Shift pressed, and type 00A0 for it on Linux. Also, opening characters map might help too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.