Angular2 is there a way to set bootstrap col dynamically?

Is it possible to use an If statement to set the column width of the div? I have got different div elements like this:

    <div class="col-xs-3">
        <select class="form-control" [(ngModel)]="selectedPrototypeSelector" (ngModelChange)="onPrototypeChange()">
            <option *ngFor="#p of prototypes" [value]="p.selector">
                {{ p.selectorName }}
            </option>
        </select>
    </div>

    <div class="col-xs-1" *ngIf="prototype?.valueType === 'Set'">
       <p class="text-center">If</p>
   </div>

How can I change the col-xs-3 above to col-xs-2 for example when prototype?.valueType === 'Set'

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

Use ngClass:

<div [ngClass]="{
    'col-xs-3': prototype?.valueType !== 'Set',
    'col-xs-2': prototype?.valueType === 'Set'}"> 

See also https://angular.io/docs/ts/latest/api/common/NgClass-directive.html

Jason
Guest

I would leverage NgClass for this:

<div [ngClass]="{'col-xs-2': prototype?.valueType === 'Set', 'col-xs-3': 'prototype?.valueType !== 'Set''}">