How to assign two values in ng-click?

Asked

Viewed 220 times

2

I have this html body that will invert the boolean variable d.expandedBlog when clicked. It is working normally.

<div class="article-blog-icon-comment">
    <i class="fa fa-commenting-o article-blog-menu-topbar" 
    ng-click="d.expandedBlog = !d.expandedBlog" pr-expand-article="d.article.uid"
    expandedBlog="d.expandedBlog"></i>
</div>

But now I want the same html body to also invert the variable d.expanded.

I tried to do it that way:

<div class="article-blog-icon-comment">
    <i class="fa fa-commenting-o article-blog-menu-topbar" 
    ng-click="d.expandedBlog = !d.expandedBlog, d.expanded = !d.expanded" 
    pr-expand-article="d.article.uid"
    expandedBlog="d.expandedBlog" expanded="d.expanded"></i>
</div>

But it is giving syntax error, I do not know the syntax to do this kind of thing. What could be done here?

1 answer

2


You can declare more than one inline mode command in the directive ng-click separating the commands with ;, just like writing in normal code:

[...]
ng-click="d.expandedBlog = !d.expandedBlog; d.expanded = !d.expanded" 
[...]

However, I advise you to consider writing a function in the controller to perform these commands for clarity.

  • 1

    +1! It may be valid to comment on which expressions ng-click are normally interpreted by the Angularjs parser, which is why you can create discrete sequences of expressions. I also agree that a role would be the best place to aggregate these actions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.