2

My question is in regards to an answer I found on Stack Overflow.

AngularJS: What's the best practice to add ngIf to a directive programmatically?

This strategy works perfect with one custom ng-if directive and the ng-if directive however what if you wanted multiple. I have spent hours trying to come up with something but can not think of a clean way to do this. Has anyone out there created a strategy for multiple custom ng-if directives?

Community
  • 1
  • 1

1 Answers1

3

Just use one and bind it to a function on the controller's scope that sorts out whatever complexities you have and returns a single boolean.

Paul
  • 35,689
  • 11
  • 93
  • 122
  • This is an attempt to extract "whatever complexities" out of the controller's scope. `` **is-logged-in** and **can-use-button** contains logic that I would like to re-use and together alongside of an **ng-if** as well. – Christopher Jean-Marie Trudel Aug 30 '16 at 13:17
  • This code example would have been great in your question. What you're actually showing is multiple custom directives, which are in this case applied to your button but don't have to be. – Paul Aug 30 '16 at 13:23