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
\( random text \)
$scope.gridOptions = { data : $scope.myData };
?