如何将 ng-click 与多个表达式一起使用? [英] How to use ng-click with multiple expressions?

查看:31
本文介绍了如何将 ng-click 与多个表达式一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ng-click 来执行多个表达式.我想在模型上设置一个值,并从 $scope 调用一个方法,如下所示:

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>

我有 && 分隔我想要执行的两个不同表达式的地方.我知道我可以添加一个方法来在控制器中做这两件事.我应该这样做,还是有办法直接从 ng-click 内部执行两个表达式?

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?

推荐答案

只需使用';'而不是 '&&'分隔表达式应该适合您:

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>

这篇关于如何将 ng-click 与多个表达式一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆