How to pass parameteres to modal?

前端 未结 6 1990
既然无缘
既然无缘 2021-02-07 10:29

That\'s the way I use the ng2-bootstrap modal:

import {Component} from \'@angular/core\';
import {NgbModal} from \'@ng-bootstrap/ng-bootstrap\';

@Component({
           


        
6条回答
  •  囚心锁ツ
    2021-02-07 10:44

    Anyone still stumbling onto this might find this handy, all you need to do is declare a field inside your ModalComponent like this:

     modalHeader: string;
     advertiser: Advertiser;
    

    You can set these fields by doing the following when you are opening a modal.

    advertiserModalShow() {
        const activeModal = this.modalService.open(AdvertiserModal, { size: 'lg' });
        activeModal.componentInstance.modalHeader = 'Advertiser';
        activeModal.componentInstance.advertiser = this.selectedAdvertiser;
    }
    

    In your template you can access them like this:

    value={{advertiser.code}}
    

    Hope this helps.

提交回复
热议问题