user3194721
user3194721

Reputation: 815

AngularJS pass Object onClick

I want to pass object in onClick event. I'm getting alert like [object Object] I need inside data also.

View:

 <div ng-repeat="action in category.Actions">
    <a ng-click=" actionclick(action)"> {{action.Name}}</a>          
   </div>

Controller:

  $scope.actionclick = function (action) {
               alert("Option Name is " + action);
           };

Upvotes: 1

Views: 685

Answers (1)

Ilan Frumer
Ilan Frumer

Reputation: 32397

Every object in javascript outputs [object Object] when coerced into a string unless it's prototype overrides the native toString method.

the plus operator coerce all objects into strings if one of it's operands is of type string.

so these are equal:

("Option Name is " + action) === ("Option Name is " + action.toString())

To see the object itself use the console (developer tools):

console.log(action)

What you probably wanted to do is to reference the name property inside the object:

"Option Name is " + action.name

Upvotes: 2

Related Questions