3

I want to make a custom modal. The problem is I dont know how to dynamically load the template url into the modal. I can do everything but dynamically load the url or another similar approach.

Thanks, MW

matt2405
  • 171
  • 2
  • 13
  • 1
    You might get some ideas from http://stackoverflow.com/questions/36566698/cant-initialize-dynamically-appended-html-component-in-angular-2/36566919#36566919 – Günter Zöchbauer Jun 30 '16 at 18:42

1 Answers1

2

It's simple! Just create a component that represents your modal and use ngTransclusion to insert html inside the component. Example:

// my-modal.component.ts
import {Component} from 'angular2/core';

@Component({
  selector: 'my-modal',
  template: `
    <div>
      <ng-content></ng-content>
    </div>
  `
})
export class MyModal{}

using the modal:

// app.component.ts
import {Component} from 'angular2/core';
import {MyModal} from './my-modal.component';

@Component({
  selector: 'my-app',
  template: `
    <div class="app">
      <my-modal>
        This is my transcluded content inside my modal!
      </my-modal>
    </div>
  `,
  directives: [
    MyModal
  ]
})
export class AppComponent {}

NgTransclusion is a builtin tool, so you don't need to import nothing!