Function data binding arguments with angular in ng-click

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

Error: [$ parse: syntax] Syntax error: token ':' is not the main expression in column 1 of the expression [: notification], starting with [: notification].

HTML snippet that results in an error:

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

HTML snippet that is not processed with angular:

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

IMPORTANT: notificationanalyzed with repetition

<div(ng-repeat="notification in notifications")></div>
+4
source share
1 answer

index.html, "" -

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

main.js -

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

app.controller('MainCtrl', function($scope) {
$scope.go = function() {
//write code here.
}
});
+8

Source: https://habr.com/ru/post/1543701/


All Articles