Dynamic Colspans Angular Directive

Col 1 Col 2 Col 3 Col 4 Col 5
dynamic-colspan="{{testWidth > 2 ? 2 : 0}}" via ternary
dynamic-colspan="{{testWidth}}" via scope variable
dynamic-colspan="{{ {4: fullWidth} }}" via object
dynamic-colspan="{{ {3: !fullWidth, 5: fullWidth} }}" via test
dynamic-colspan="{{ userWidth }}" set via row below
{{num}}
Notes

Allows setting colspan via the following:

  • direct value, such as dynamic-colspan="2"
  • variables, such as dynamic-colspan="row.columnWidth"
  • an expression, such as dynamic-colspan="testWidth > 2 ? 2 : 0"
  • object for multiple rules, (in this pattern, the property key is desired number of columns to span, similar to ng-class ), such as dynamic-colspan="{99: rowType === 'heading', 1: rowType === item, 3: rowType === data}"

For more usages, play with the HTML source in the CodePen .