Migrating Modals from Semantic UI to Bootstrap

In this document we'll be using SUI for ng2-semantic-ui and Bootstrap for ng-bootstrap.

Template-based modals

Migrating templates

SUI templates follow this structure:

  <ng-template  #templateBasedModal let-context let-modal="modal">
    <div class="header"> ... </div>
    <div class="content"> ... </div>
    <div class="actions">
      <button id="..." class="..."
              (click)="modal.approve( ... )" ... </button>
      <button id="..." class="..." 
              (click)="modal.deny(  ... )"> ... </button>
    </div>
  </ng-template>

Bootstrap templates follow this structure instead:

<ng-template #templateBasedModal let-modal>
    <div class="modal-header">
        <div class="modal-title"> ... </div>
        <button class="btn close" type="button" (click)="modal.dismiss( ... )">
            &times;
        </button>
    </div>

    <div class="modal-body">
        ...
    </div>

    <div class="modal-footer">
        <button type="button" class="..." (click)="modal.close( ... )"> ... </button>
    </div>
</ng-template>

Notes

Migrating components

You use SUI template modals as follows:

export interface IMContext {
    data: string;
}

@ViewChild('modalTemplate', { static: false })
templateBasedModal: ModalTemplate<IMContext, string, string>
    ...

constructor( private modalService: SuiModalService, ... ) {
    ...
}

    ...

const config = new TemplateModalConfig<IMContext, string, string>(this.templateBasedModal);
config.closeResult = '...';
config.context = { data: ... };
    ...

this.modalService.open( config )
    .onApprove( result => { ... })
    .onDeny(    result => { ... });

where IMcontext is an interface describing the contex object that will be passed to the template. (Obviously, it doesn't need to be IMcontext, any name will do.)

You use Bootstrap templates as follows:

@ViewChild('templateBasedModal', { static: false })
templateBasedModal: TemplateRef<any>;
    ...

constructor( private modalService: NgbModal, ... ) {
    ...        
}

    ...

this.modalService.open( this.templateBasedModal ).result
    .then(  accept => { ... })
    .catch( reason => { ... });

Notes

Component-based modals

TO-DO