isaacplmann / ngx-contextmenu

An Angular component to show a context menu on an arbitrary component
MIT License
248 stars 91 forks source link

[visible] with negative value #148

Open elementalTIMING opened 5 years ago

elementalTIMING commented 5 years ago

As far as I understood the [visible] get a function that returns true or false. Is there any way to invert the result?

For example: I have two different menu items. The one shall be shown when a variable value is true and the other value shall be hidden - and vice versa.

The only working solution I found is to have two different functions to call - but this is a bit "strange". Is there any other way to do this?

isaacplmann commented 5 years ago

Not really any other way.

You could theoretically have a function return a function like this:

[visible]="isVisible(true)"
isVisible(oppositeDay: boolean) {
  return () => {
    if(oppositeDay) {
      return false;
    } else {
      return true;
    }
  }
}