5

I am using ng-click to call a function with arguments I get from the $scope. Unfortunately either are the arguments not processed from angular or I get this error:

Error: [$parse:syntax] Syntax Error: Token ':' not a primary expression at column 1 of the expression [:notification] starting at [:notification].

HTML snippet that results in error:

<div ng-click="goToNotif({{notification.id}})"></div>

HTML snippet not being processed from angular:

<div ng-click="goToNotif(notification.id)"></div>

IMPORTANT: notification is parsed from a repeat

<div(ng-repeat="notification in notifications")></div>
2
  • the second one should definitely work ..make sure you defined goToNotif as $scope.goToNotif=function(){} Commented Jun 7, 2014 at 20:45
  • don't use expression syntax {{ }}for arguments of a scoped function Commented Jun 7, 2014 at 23:18

1 Answer 1

9

Here is the code for index.html, define "notifications" seperately -

<div ng-app="MyApp">
    <div ng-controller="MainCtrl">
    <div(ng-repeat="notification in notifications")>
        <div ng-click="go(notification.id)"></div>
    </div>
</div>
</div>

In main.js -

var app = angular.module('MyApp', []);

app.controller('MainCtrl', function($scope) {
$scope.go = function() {
//write code here.
}
});
Sign up to request clarification or add additional context in comments.

1 Comment

I was trying to do this inside a directive template and everything else uses the binding syntax ( {{id}} ).....EXCEPT this part - was banging my head on the desk......thanks!

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.