Good afternoon!
I have the following component
import { Component, Input, ElementRef, HostListener, OnDestroy, OnInit } from '@angular/core';
/**
* This class represents the navigation bar component.
*/
@Component({
moduleId: module.id,
selector: 'sd-notification',
templateUrl: 'notification.component.html',
styleUrls: ['notification.component.css'],
})
export class NotificationComponent implements OnDestroy, OnInit {
constructor(private el: ElementRef) { }
@Input() mensagem: string;
@Input() time: number = 2000;
@Input() tipo: string ="";
isVisible = true;
ngOnInit() {
setTimeout(() => {
this.ngOnDestroy();
}, this.time);
}
ngOnDestroy() {
this.isVisible = false;
setTimeout(() => {
this.el.nativeElement.remove();
}, 1000);
}
private _timeOut: number = 3000;
public get timeOut(): number {
return this._timeOut;
}
public set timeOut(v: number) {
this._timeOut = v;
}
fechar() {
this.ngOnDestroy();
}
}
I want to inject it into another Component, in javascript it would look something like this:
import { Component } from '@angular/core';
/**
* This class represents the lazy loaded ServicoComponent.
*/
@Component({
moduleId: module.id,
selector: 'sd-servico',
templateUrl: 'servico.component.html',
styleUrls: ['servico.component.css']
})
export class ServicoComponent {
constructor(public service: ServicoService) {
}
salvar(servico?: Servico) {
document.body.innerHTML += '<sd-notification tipo="syo-success" mensagem="Dados salvos com sucesso!"></sd-notification>'; // Mas isso não compila a diretiva ds-notification....
}
}
But Angular2 does not compile this directive.