Mattia Vandi
Mattia Vandi

Reputation: 13

AngularJS Syntax Error when trying to parse an MongoDB ObjectId

I'm new to MEAN stack applications so I'm asking for help.
Everytime AngularJS tries to parse the following code

<button type="button" class="btn btn-link pull-right" ng-click="delete({{ post._id }});"><span class="glyphicon glyphicon-trash"></span></button>

Displays in the console the following error:

Error: [$parse:syntax] http://errors.angularjs.org/1.4.3/$parse/syntax?p0=%7B&p1=invalid%20key&p2=9&p3=delete(%7B%7B%20post._id%20%7D%7D)%3B&p4=%7B%20post._id%20%7D%7D)%3B 
    at Error (native) https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js:12330
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:6:416
    at Object.q.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:209:32)
    at Object.q.object (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:208:327)
    at Object.q.primary (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:205:335)
    at Object.q.unary (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:205:174)
    at Object.q.multiplicative (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:204:434)
    at Object.q.additive (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:204:261)
    at Object.q.relational (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:204:96)
    at Object.q.equality (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:203:425) <button type="button" class="btn btn-link pull-right" ng-click="delete({{ post._id }});">

But when I inspect the delete button I can find this:

    <button type="button" class="btn btn-link pull-right" ng-click="delete(55ba1c2d6411b92c1715490c);"><span class="glyphicon glyphicon-trash"></span></button>

Could some one help me to fix this problem?

Upvotes: 0

Views: 359

Answers (1)

oznu
oznu

Reputation: 1694

Remove the{{ }} from the ng-click attribute, it is not required in this case:

ng-click="delete(post._id);"

Why?

https://docs.angularjs.org/api/ng/directive/ngClick

The ng-click directive accepts an expression which is evaluated on click.

Upvotes: 1

Related Questions