I'm trying to implement a simple loading icon directive:
import { Directive, ElementRef, Renderer2, Input, OnChanges } from '@angular/core';
@Directive({
selector: '[appLoading]',
})
export class LoadingDirective implements OnChanges {
@Input() appLoading: boolean;
constructor(private elRef: ElementRef, private renderer: Renderer2) {
}
ngOnChanges() {
if (this.appLoading) {
this.renderer.addClass(this.elRef.nativeElement, 'loading-wrap');
this.elRef.nativeElement.innerHtml = '<div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>';
} else {
this.renderer.setStyle(this.elRef.nativeElement, 'display', 'none');
}
}
}
In my template I have:
<div [appLoading]="isLoading"></div>
But it looks like Angular doesn't apply my styles for loading spinner in styles.css for the content added into innerHtml. The styles work for the main element with class 'loading-wrap' though.