Skip to content Skip to sidebar Skip to footer

Ng2-bootstrap, Call Modal Defined In Child Component From Parent Compent

I am using ng2-bootstrap for the modal stuff. I am trying to separate my modals and my other components apart. So I have the following files: addPlaylist.modal.ts import {Component

Solution 1:

Your solution might look something like this:

ChildComponent

@Component({
  ...
  exportAs: 'child'  <== add this line
})
exportclassAddPlaylistModalComponent {
  @ViewChild('lgModal') lgModal; <== reference to Modal directive
  show(){   <== public method
    this.lgModal.show(); 
  }
}

ParentComponent

template: `<a class="btn btn-success" (click)="c.show()">Add</a>
           <addplaylist-modal #c="child"></addplaylist-modal>`

See also the completed sample here https://plnkr.co/edit/2UAB7lpqqAvchTsLwzr6?p=preview

Post a Comment for "Ng2-bootstrap, Call Modal Defined In Child Component From Parent Compent"