我想将子模态传递给我的父函数。我使用了这个Modal
app.html
<div class="head"><button class="headbtn" (click)="Popup(modal)">Add</button></div>
<div>
<div class="centerDiv text-center" *ngFor="let hero of list">
<div>
<button class="glyphicon glyphicon-trash operation"></button>
<button class="glyphicon glyphicon-pencil operation" (click)="Popup(modal)"></button>
</div>
<div><h4>{{hero.Name}}</h4></div>
</div>
</div>
<custom-modal></custom-modal>
customModal.html
<modal #modal> <---- this Modal
<modal-header [show-close]="true">
<h4 class="modal-title">I'm a modal!</h4>
</modal-header>
<modal-body>
Hello World!
</modal-body>
<modal-footer [show-default-buttons]="true"></modal-footer>
app.component.ts
export class AppComponent {
list = [{ "Name": "App 1" }];
Popup(modal) { <--- I am getting this modal undefined.
debugger;
modal.open();
}
}
我该怎么做?
答案 0 :(得分:0)
您可以尝试这样的事情:
<强> CustomModalComponent 强>
@ViewChild('modal') public modal: ModalComponent;
<强> app.html 强>
(click)="Popup(customModal.modal)"
...
<custom-modal #customModal></custom-modal>
<强> Plunker Example 强>
另见