rpiper rpiper - 2 months ago 5
AngularJS Question

How do I resolve this syntax error caused by .?

The error message I am getting is:


Syntax Error: Token '.' is unexpected, expecting [}] at column 23 of the expression [] starting at [{4}].


The offending html that is causing the issue.

<tr ng-repeat="record in key_table">

<td ng-repeat="data in record">
{[{ data }]}
</td>
<td>
<button type="button" class="btn btn-default" ng-click="$ctrl.open({[{ record.KeyNum }]})">Open me!</button>
</td>
<td>
<button>Edit</button> <button>Delete</button>
</td>
</tr>


The open function in angularjs:

angular.module('KeyManager').controller("KeyController", function( httpFactory, $uibModal) {
$ctrl = this;
$ctrl.open = function () {
var modalInstance = $uibModal.open({
animation: true,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'RecordViewer.html',
controller: 'RecordViewerInstanceCtrl',
controllerAs: '$ctrl',
size: "lg",
resolve: {
items: function (keyNum) {
httpFactory.getRecord(keyNum).then(
function(response) {
$ctrl.items = response.data[0];
},
function(response) {
console.log(response);
$ctrl.items = [];
}
);
return $ctrl.items;
}
}
});
});


Also, note that I am doing this in a twig file so start and and end symbols have been changed to "{[{" and "}]}" respectively.

Added Information:

I have tried switching the ng-click directive to

"$ctrl.open(record.KeyNum)"


but this only prints out the literal string record.KeyNum which is explain here so @smarx comment is the answer.

Answer

I think you just want $ctrl.open(record.KeyNum).

Comments