0

我有一个组件,它包含一个模式。

<div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title pull-left">Large modal</h4>
          <button type="button" class="close pull-right" (click)="lgModal.hide()" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          {{current}}
        </div>
      </div>
    </div>
  </div>

我打开模态@ViewChild('lgModal') modal;并调用this.modal.show();

但我想分离 HTML,那么是否可以B从组件中调用组件A

4

1 回答 1

0

我建议您创建一个对话组件服务,无论您身在何处都可以使用它。您只需将其作为服务注入并使用提供的方法在对话框中填充相关内容。

一个例子,刚刚在Stackoverflow 线程上找到

于 2017-07-02T16:50:53.003 回答