0

I have an element as below :

<a class="previous i-previous  fa fa-caret-left" href=""
    ng-click="setPage(currentPage-1)"
    ng-hide="currentPage == 0">
</a>

I had this code working but now I have this exception :

Error: [$parse:syntax] http://errors.angularjs.org/1.2.26/$parse/syntax?p0=undefined&p1=is%20unexpected%2C%20expecting%20%5B)%5D&p2=null&p3=setPage(currentPage&p4=setPage(currentPage

The code that causes the exception is :

ng-click="setPage(currentPage-1)"

When i removed -1 it works so it seems the problem is about that part.

What might be the cause of this exception?

EDIT :

I have this code in my controller :

$scope.currentPage = 0;
$scope.setPage = function (page) { 
        $scope.currentPage = page;
    };
2
  • try setPage(--currentPage) Commented Jun 25, 2015 at 9:34
  • It's running correctly. jsfiddle.net/U3pVM/16666 Commented Jun 25, 2015 at 9:44

3 Answers 3

2

It is caused by batarang in Chrome, disable it or use other browser to test, or use incognito mode.

https://stackoverflow.com/a/31006278/5039495

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

4 Comments

What do you want to say ?
Wow, it caused me for 2 hours. Thanks.
@Vineet setPage(currentPage-1) is valid angular syntax, but it get parsed incorrectly on chrome with batarang. You can call it a false positive.
@cuneytyvz Yea I spent few hours on it as well, hope they will fix it soon
1

Just try

ng-click="currentPage = currentPage - 1; setPage(currentPage)"

4 Comments

I have this method in other parts of my code and use it for pagination view like "currentpage + 1" also. I'm going to try this but i think "currentPage-1" is also needs to be working.
great thanks, it worked. But i still didn't get why the other one does not.
Simply, your ng-click function sends the value first to controller and then decreasing it by 1.
i mean i didn't get why the version in the question does not work. And also currentPage-- also didn't work but 'ng-click="currentPage = currentPage - 1; setPage(currentPage)"' did work.
0

It's running correctly. check fiddle

<div ng-app>

  <div ng-controller="TodoCtrl">
    <a  href=""
    ng-click="setPage(currentPage-1)"
    ng-hide="currentPage == 0">test
</a>
  </div>
</div>



function TodoCtrl($scope) {
    $scope.currentPage = 5;
$scope.setPage = function (page) { 
        $scope.currentPage = page;
    };
}

http://jsfiddle.net/U3pVM/16666/

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.