0

I know I can use ng-if to do conditionals like this:

  td.icon(ng-if="isAuthor()", colspan="2")
  td.icon(ng-if="!isAuthor()", colspan="3")

But it seems a bit over-wordy for something simple. Is there a way to do:

  td.icon(ng-if="!isAuthor()", colspan="{{if isAuthor(): 2 else 3}}")
Harry
  • 52,711
  • 71
  • 177
  • 261
  • Angular added support for the ternary operator (which is what you are asking about) in 1.1.5 - [See this question](http://stackoverflow.com/questions/12008580/a-ternary-in-angular-templates-angularjs) – Dan Jun 26 '13 at 04:49
  • What's this syntax? Angular goes on HTML. Like ``. I must be missing something. – jpsimons Jun 26 '13 at 06:04

1 Answers1

0

You can have a function that does that!

td.icon(colspan="getColspan()")

And in your controller:

$scope.getColspan = function () {
    if (isAuthor()) {
        return 2;
    } else {
        return 3;
    }
};
callmekatootie
  • 10,989
  • 15
  • 69
  • 104