Я планирую добавить динамический компонент в DOM, если вызывается show(). Я знаю, что есть решение с ngIf или [hidden], чтобы скрыть его и использовать в качестве директивы, но я не поклонник этого решения, потому что я не хочу объявлять его в своем HTML.
import {Component} from 'angular2/core';
import {InfoData} from '../../model/InfoData';
@Component({
selector: 'Info',
templateUrl: './components/pipes&parts/info.html',
styleUrls: ['./components/pipes&parts/info.css']
})
export class Info{
infoData: InfoData;
public show(infoData: InfoData) {
this.infoData= infoData;
document.body.appendChild(elemDiv); <----- Here?
}
}
а затем объявляю это как провайдера, поэтому я могу вызвать show().
import {Component} from 'angular2/core';
import {Info} from './components/pipes&parts/Info';
@Component({
selector: 'Admin',
templateUrl: './Admin.html',
styleUrls: ['./Admin.css'],
directives: [Info],
providers: [Info]
})
export class Admin {
constructor(private info: Info) {
info.show(); <---- append the Info Element to DOM
}