Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data-binding arguments of a function with AngularJS in ng-click

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>
like image 583
Boyan Hristov Avatar asked Jun 07 '14 20:06

Boyan Hristov


1 Answers

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.
}
});
like image 60
Manvi Avatar answered Nov 01 '22 07:11

Manvi