4

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?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Dima Grigoriev
  • 357
  • 5
  • 22

1 Answers1

0

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

Community
  • 1
  • 1
Shilpa Nagavara
  • 1,055
  • 2
  • 16
  • 31