Skip to content

Commit

Permalink
fix: 🐛 fix view resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBasal committed Aug 9, 2021
1 parent 5b3209a commit 4e34c35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
ChangeDetectionStrategy,
Directive,
Injector,
Input,
NgModule,
OnChanges,
OnDestroy,
OnInit,
SimpleChanges,
TemplateRef,
ViewContainerRef,
} from '@angular/core';
Expand All @@ -17,27 +18,25 @@ import { DynamicViewComponent } from './dynamic-view.component';
@Directive({
selector: '[dynamicView]',
})
export class DynamicViewDirective implements OnInit, OnDestroy {
@Input('dynamicView')
set view(content: Content) {
this._view = content;
this.resolveContentType();
}
export class DynamicViewDirective implements OnInit, OnChanges, OnDestroy {
@Input('dynamicView') view: Content;
@Input('dynamicViewInjector') injector: Injector;
@Input('dynamicViewContext') context: any;

private viewRef: ViewRef;
private _view: Content;
get view() {
return this._view;
}

constructor(private defaultTpl: TemplateRef<any>, private vcr: ViewContainerRef, private viewService: ViewService) {}

ngOnInit() {
this.resolveContentType();
}

ngOnChanges(changes: SimpleChanges) {
if (changes.view && !changes.view.isFirstChange()) {
this.resolveContentType();
}
}

resolveContentType() {
this.viewRef?.destroy();
if (isString(this.view)) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/hello/hello.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Component, Inject, OnInit, Optional } from '@angular/core';
styleUrls: ['./hello.component.scss'],
})
export class HelloComponent implements OnInit {
constructor(@Optional() @Inject('name') public name: string) {}
constructor(@Inject('name') public name: string) {}

ngOnInit(): void {}
}

0 comments on commit 4e34c35

Please sign in to comment.