Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions packages/common/src/directives/ng_if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri
*
*/
@Directive({selector: '[ngIf]'})
export class NgIf {
private _context: NgIfContext = new NgIfContext();
private _thenTemplateRef: TemplateRef<NgIfContext>|null = null;
private _elseTemplateRef: TemplateRef<NgIfContext>|null = null;
private _thenViewRef: EmbeddedViewRef<NgIfContext>|null = null;
private _elseViewRef: EmbeddedViewRef<NgIfContext>|null = null;
export class NgIf<T = any> {
private _context: NgIfContext<T> = new NgIfContext();
private _thenTemplateRef: TemplateRef<NgIfContext<T>>|null = null;
private _elseTemplateRef: TemplateRef<NgIfContext<T>>|null = null;
private _thenViewRef: EmbeddedViewRef<NgIfContext<T>>|null = null;
private _elseViewRef: EmbeddedViewRef<NgIfContext<T>>|null = null;

constructor(private _viewContainer: ViewContainerRef, templateRef: TemplateRef<NgIfContext>) {
constructor(private _viewContainer: ViewContainerRef, templateRef: TemplateRef<NgIfContext<T>>) {
this._thenTemplateRef = templateRef;
}

Expand All @@ -120,15 +120,15 @@ export class NgIf {
}

@Input()
set ngIfThen(templateRef: TemplateRef<NgIfContext>|null) {
set ngIfThen(templateRef: TemplateRef<NgIfContext<T>>|null) {
assertTemplate('ngIfThen', templateRef);
this._thenTemplateRef = templateRef;
this._thenViewRef = null; // clear previous view if any.
this._updateView();
}

@Input()
set ngIfElse(templateRef: TemplateRef<NgIfContext>|null) {
set ngIfElse(templateRef: TemplateRef<NgIfContext<T>>|null) {
assertTemplate('ngIfElse', templateRef);
this._elseTemplateRef = templateRef;
this._elseViewRef = null; // clear previous view if any.
Expand Down Expand Up @@ -161,9 +161,9 @@ export class NgIf {
public static ngIfUseIfTypeGuard: void;
}

export class NgIfContext {
public $implicit: any = null;
public ngIf: any = null;
export class NgIfContext<T = any> {
public $implicit: T|null = null;
public ngIf: T|null = null;
}

function assertTemplate(property: string, templateRef: TemplateRef<any>| null): void {
Expand Down