I'm struggling here (I am new to programming still), I have an ng-repeat that is repeating a list (page on Pages) which displays the correct number on the front end (i.e. 1) but, when I try and use the same for the ng-click, it will throw this error:
Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 31 of the expression [getCtrlScope().currentPage = {{ page }}] starting at [{ page }}].
What is strange is that it will display it correctly within the HTML code correctly but will not function.
Code:
<li class="page-item" ng-repeat="page in Pages">
<a class="page-link" ng-click="getCtrlScope().currentPage = {{ page }}">{{ page }}</a>
</li>
What shows when rendered in HTML:
<li class="page-item ng-scope" ng-repeat="page in Pages">
<a class="page-link waves-effect ng-binding" ng-click="getCtrlScope().currentPage = 2">2</a>
</li>
JS
var MyApp = angular.module('MyApp', []);
MyApp.controller('MyCtrl', function ($scope, $filter) {
$scope.Users = tJSONData;
$scope.currentPage = 0;
$scope.pageSize = 3;
$scope.search = '';
$scope.Pages = [1, 2, 3];
$scope.getData = function () {
return $filter('filter')($scope.Users, $scope.search)
}
$scope.updatePage = function() {
$scope.$apply(function () {
$scope.Users = tJSONData
})
}
$scope.numberOfPages = function () {
return Math.ceil($scope.getData().length / $scope.pageSize);
}
$scope.getCtrlScope = function () {
return $scope;
}
});
MyApp.filter('startFrom', function () {
return function (input, start) {
start = +start; //parse to int
return input.slice(start);
}
});
I've looked around but pretty much all the fixes have been by removing {{ }}, some it has worked for because it was rendering incorrectly but it seems mine is rendering correctly.
If anyone has any ideas, it'd be a great help :)
{{}}in ng-xx directives expressions.