简体   繁体   中英

Angular2 pass data to modal

i'm new in angular2 + typescript. And i need realize confirmation modal by click on button in table

This is table

<div style="margin-top: 10px">
    <table id="recruitersTable" class="table table-striped center" [ngBusy]="data">
        <tr>
            <th>{{ 'RECRUITER_NAME_AND_SURNANE_COLUMN' | translate }}</th>
            <th>{{ 'RECRUITER_CODE_COLUMN' | translate }}</th>
            <th>{{ 'RECRUITER_ACTION_DOLUMN' | translate}}</th>
            <th></th>
        </tr>
        <tr *ngFor="let recruiter of recruiters">
            <td>{{ recruiter.Name }}</td>
            <td>{{ recruiter.Code }}</td>
            <td>
                <a class="btn btn-xs btn-default" data-target="#confirm" role="button" data-toggle="modal">
                    <span class="glyphicon glyphicon-ban-circle"></span>
                </a>
            </td>
            <td></td>
        </tr>
    </table>
</div>

This is confirmation modal

<div id="confirm" class="modal fade in" aria-labelledby="modallabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove"></span></button>
            <h3 id="modalLabael">Block recruiter</h3>
        </div>
        <div class="modal-body">
            <h3 id="modalLabael">Are you sure that you want block this recruiter?</h3>
        </div>
        <div class="modal-footer">
            <button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Cancel</button>
            <button class="btn btn-success" (click)="BlockRecruiter(recruiter.code)">Block</button>
        </div>
    </div>
</div>

And i need implement function by click 'success' on confirm modal, but data in another div. Can someone explain me?

You could either use EventEmitter if your modal component is contained in the parent component - Check here --> https://angular.io/docs/ts/latest/api/core/index/EventEmitter-class.html

Or you could use a service that returns a subject as an observable. The parent component can subscribe to the observable while the modal alerts the service on confirmation. Check how the alert.service has been written and used here --> Angular 2: Displaying icons in navbar on authentication

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM