I'm trying to create a loading indicator/overlay in Angular2 that I can add to any container div. When a dynamic boolean property like isLoading
changes, it should grey out the div and show a spinning indicator, and disappear again after the property changes back.
I got a working solution:
@Component({
selector: 'loading-overlay',
styleUrls: ['...'],
template: `
<div class="bg-loading" *ngIf="isLoading">
<h3><span class="glyphicon glyphicon-refresh spinning"></span></h3>
</div>`
})
export class LoadingOverlay {
@Input()
isLoading: boolean;
}
And usage:
<div> <!-- container for whatever -->
<loading-overlay [isLoading]="dynamicProp"></loading-overlay>
<!-- ... other content -->
</div>
So far so good, but this is hard to get right with styling for different use cases, mostly to make the margins/paddings look good in different containers.
So I want to make this whole thing into an attribute directive like so:
<div loading-overlay="dynamicProp"> <!-- container for whatever -->
<!-- content ... -->
</div>
I'm pretty sure this should be easy, but I can't find anything useful in the docs or via googling. It feels like I should dynamically add/remove the overlay div, but I'm not sure if this is the right approach, or even how to do it.