NetanelBasal
8/17/2018 - 7:40 AM

ngSubscribe-1.directive.ts

export class NgSubscribeContext {
  $implicit = null;
  ngSubscribe = null;
}

@Directive({
  selector: '[ngSubscribe]'
})
export class NgSubscribeDirective implements OnInit, OnDestroy {

  private observable: Observable<any>;
  private context: SubscribeContext = new NgSubscribeContext();
  private subscription: Subscription;

  @Input()
  set ngSubscribe(inputObservable: Observable<any>) {
   
  }

  constructor(
    private viewContainer: ViewContainerRef,
    private cdr: ChangeDetectorRef,
    private templateRef: TemplateRef<any>
  ) {}

  ngOnInit() {
    this.viewContainer.createEmbeddedView(this.templateRef, this.context);
  }

  ngOnDestroy() {
    this.subscription && this.subscription.unsubscribe();
  }
}