Angular2将数据传递给模态

时间:2016-11-12 12:14:38

标签: html angular typescript bootstrap-modal

我是angular2 +打字稿的新手。我需要通过点击表格中的按钮来实现确认模式

这是表格

<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>

这是确认模式

<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>

我需要实现功能,点击确认模式上的'成功',但另一个div中的数据。有人可以解释一下吗?

1 个答案:

答案 0 :(得分:0)

如果您的模态组件包含在父组件中,您可以使用EventEmitter - 在此处查看 - &gt; https://angular.io/docs/ts/latest/api/core/index/EventEmitter-class.html

或者您可以使用将主题作为可观察对象返回的服务。父模块可以订阅observable,而模态会在确认时提醒服务。检查alert.service是如何编写和使用的 - &gt; Angular 2: Displaying icons in navbar on authentication