Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Directive, Input, TemplateRef, ViewContainerRef, OnInit, AfterViewInit } from '@angular/core';
- import { FeatureService } from '../services/feature.service';
- /**
- * Add the template content to the DOM when feature is enabled
- * Usage:
- * <div *feature="'exampleFeature'"></div>
- */
- @Directive({ selector: '[feature]' })
- export class FeatureDirective implements OnInit {
- @Input() feature: string;
- constructor(
- private templateRef: TemplateRef<any>,
- private viewContainer: ViewContainerRef,
- private featureService: FeatureService,
- ) {}
- ngOnInit() {
- this.featureService.changes().subscribe((features: any) => {
- if (this.featureService.hasFeature(this.feature)) {
- this.viewContainer.createEmbeddedView(this.templateRef);
- } else {
- this.viewContainer.clear();
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment