Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  193] [ 5]  / answers: 1 / hits: 94146  / 11 Years ago, mon, november 11, 2013, 12:00:00

I want to use ng-click to perform multiple expressions. I want to both set a value on a model, and call a method from the $scope, like this:



<a ng-click=navigation.book = book && bookSvc.showBook(book) href=#{{book.id}}>{{book.title}}</a>


Where I have && separating the two different expressions I want to perform. I know I could just add a method that does both things in the controller. Should I just do that, or is there a way to perform two expressions directly from inside ng-click?


More From » angularjs

 Answers
46

Simply using ';' instead of '&&' to separate the expression should work for you:



<a ng-click=navigation.book = book; bookSvc.showBook(book) href=#{{book.id}}>{{book.title}}</a>

[#74346] Sunday, November 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daryldeontaeh

Total Points: 46
Total Questions: 97
Total Answers: 105

Location: Maldives
Member since Sat, Jan 29, 2022
2 Years ago
;