DEVHIDE
  • Home (current)
  • About
  • Contact
  • Cookie
  • Home (current)
  • About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy
  • TOS
Login Or Sign up

Angular 2: NgbModal transclude in view

1.7k Views Asked by byCoder At 04 June 2017 at 21:46 2025-12-04T07:21:01.482000

Let's say i have such modal template:

<div class="modal-header">
  <h3 [innerHtml]="header"></h3>
</div>

<div class="modal-body">
  <ng-content></ng-content>
</div>

<div class="modal-footer">
</div>

and i'm calling this modal from another component so:


    const modalRef = this.modalService.open(MobileDropdownModalComponent, {
      keyboard: false,
      backdrop: 'static'
    });

    modalRef.componentInstance.header = this.text;

How can i put into NgbModal html with bindings etc? Into ng-content

javascript angular typescript ng-bootstrap ng-modal
Original Q&A
1

There are 1 best solutions below

2
Julia Passynkova Julia Passynkova On 20 June 2017 at 14:20

You can get a reference to the component instance from NgbModalRef returned by open method and set the binging there.

here is method that open the modal:

open() {
   const instance = this.modalService.open(MyComponent).componentInstance;
   instance.name = 'Julia';
 }

and here is the component that will be displayed in the modal with one input binding

export class MyComponent {
   @Input() name: string;

   constructor() {
   }
 }

===

You can pass a templateRef as input as well. Let say the parent component has

 <ng-template #tpl>hi there</ng-template>


 export class AppComponent {
   @ViewChild('tpl') tpl: TemplateRef<any>;

  constructor(private modalService: NgbModal) {
  }

 open() {
    const instance = 
    this.modalService.open(MyComponent).componentInstance;
     instance.tpl = this.tpl;
  }
}

and MyComponent:

export class MyComponentComponent {
  @Input() tpl;

  constructor(private viewContainerRef: ViewContainerRef) {
  }

  ngAfterViewInit() {
     this.viewContainerRef.createEmbeddedView(this.tpl);
  }
}

Related Questions in JAVASCRIPT

  • Angular Show All When No Filter Is Supplied
  • Why does a function show up as not defined
  • I count the time the user takes to solve my quiz using Javascript but I want the same time displayed on another page
  • Set "More" "Less" font size
  • Using pagination on a table in AngularJS
  • How to sort these using Javascript or Jquery Most effectively
  • how to fill out the table with next values in array with one button
  • State with different subviews
  • Ajax jQuery firing multiple time display event for the same result
  • Getting and passing MVC Model data to AngularJS controller
  • Disable variable in eval
  • javascript nested loops waiting for user input
  • .hover() seems to overwrite .click()
  • How to sort a multi-dimensional array by the second array in descending order?
  • How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?

Related Questions in ANGULAR

  • Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript?
  • Module '"angular2/angular2"' has no exported member 'For'
  • import syntax in typescript creating another js file in visual studio
  • Separate ts file for imports
  • How to use an AngularJS 2 component multiple times in the same page?
  • injectables not working in angular 2.0 latest build 26
  • Does angular2 bootstrap have a way to dynamically target elements like it does in angular 1.x
  • Import {} from location is not found in VS Code using TypeScript and Angular 2
  • Angular 2/Typescript: require not found
  • ng-switch in Angular2
  • Angular 2 import issue: "Zone already exported on window the object!"
  • How to make FileReader work with Angular2?
  • Writing the most basic Unit test in Angular 2?
  • Angular2: Creating child components programmatically
  • AngularJS - TypeError: Cannot read property 'canonicalUrl' of undefined

Related Questions in TYPESCRIPT

  • Use translateProvider.useLoader with Typescript
  • Optional method in base class
  • Putting Lambdas in OR statement
  • Deleting namespace in Socket IO
  • Angularjs+Typescript directive implementing $compile
  • Typescript type inference inside for loop
  • Why void functions are allowed in left part of assignment in Typescript?
  • Tools for Apache Cordova - TypeScript debugger jumps to wrong line
  • Typescript - is there a way to specify a global reference?
  • How to angularjs app.service and $q in typescript
  • include typescript file in output result build with TFS
  • Mocking Angular $window in unit test cases
  • Difference between `share()` and `publish().refCount()`
  • TypeScript: workaround for relative reference path?
  • How to define knex migrations using Typescript

Related Questions in NG-BOOTSTRAP

  • Why won't a [(ngModel)] of a radio group bind?
  • How to implement Bootstrap 4 for Angular 2 ngb-pagination
  • Angular2 Bootstrap Datepicker format date issue
  • How to pass parameteres to modal?
  • How to set the width of the dropdown in the typeahead module
  • dropdown toggle issue in navbar with ng-bootstrap (4) angular 2 (cli)
  • NgbDropdown doesn't stay open
  • How to customize the CSS for ng-bootstrap controls using Angular 2 / Bootstrap 4
  • Getting started directly on ng-bootstrap (without working on 1.5.8)
  • NgbModal error when trying to close
  • ng-bootstrap for Angular 2 datepicker does not popup the calendar
  • Issue with prepopulating ng-bootstrap's typeahead whilst relying on model driven forms
  • Angular 2 Alerts that work with Bootstrap 4, similar to Toastr
  • Display content on ngbModal when clicking on table row - Angular 2
  • stop closing the modal by clicking backdrop or outside the modal

Related Questions in NG-MODAL

  • Mock NgbModal in Angular
  • How Scroll to a div in ng-template?
  • Angular - set dropdown object value upon deleting a dropdown object is not working
  • Angular NgbModal, how to correctly close a modal window?
  • Angular2 bootstrap modal with child component
  • Detect Data Chages When Another Component Make a POST or a PUT Request
  • Can I have NgModal's HTML rendered dynamically
  • Angular 11 - mat-sort is not working in ng-modal table
  • Angular7 and NgbModal: how to remove default auto focus
  • Refresh a Select Dropdown After Saving Modal Form
  • How to not update the data after cancel or close the modal in Angular?
  • Does the windowClass property or NgbModalOptions actually do anything?
  • Group by Question and ng-model differentiation with AngularJS
  • How can I check that a form has unsaved changes before closing ng-modal in Angular 5?
  • ng-options with multiple select/Checkbox

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

Popular # Hahtags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?
.

Copyright © 2021 Jogjafile Inc.

  • Disclaimer
  • Privacy
  • TOS
  • Homegardensmart
  • Math
  • Aftereffectstemplates