-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c753b1
commit f2a93fc
Showing
6 changed files
with
127 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Directive, Input } from "@angular/core"; | ||
|
||
interface NgAsContext<T> { | ||
ngLet: T; | ||
$implicit: T; | ||
} | ||
|
||
@Directive({ selector: '[ngAs]' }) | ||
export class NgAsDirective<T> { | ||
@Input() ngAs!: T; | ||
|
||
/** @internal */ | ||
public static ngLetUseIfTypeGuard: void; | ||
|
||
/** | ||
* Assert the correct type of the expression bound to the `NgLet` input within the template. | ||
* | ||
* The presence of this static field is a signal to the Ivy template type check compiler that | ||
* when the `NgLet` structural directive renders its template, the type of the expression bound | ||
* to `NgLet` should be narrowed in some way. For `NgLet`, the binding expression itself is used to | ||
* narrow its type, which allows the strictNullChecks feature of TypeScript to work with `NgLet`. | ||
*/ | ||
static ngTemplateGuard_ngLet: 'binding'; | ||
|
||
/** | ||
* Asserts the correct type of the context for the template that `NgLet` will render. | ||
* | ||
* The presence of this method is a signal to the Ivy template type-check compiler that the | ||
* `NgLet` structural directive renders its template with a specific context type. | ||
*/ | ||
static ngTemplateContextGuard<T>(dir: NgAsDirective<T>, ctx: any): ctx is NgAsContext<Exclude<T, false | 0 | '' | null | undefined>> { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { NgAsDirective } from './ng-as.directive'; | ||
import { NgAsPipe } from './ng-as.pipe'; | ||
|
||
@NgModule({ | ||
declarations: [NgAsPipe], | ||
declarations: [NgAsPipe, NgAsDirective], | ||
imports: [], | ||
exports: [NgAsPipe], | ||
exports: [NgAsPipe, NgAsDirective], | ||
providers: [] | ||
}) | ||
export class NgAsModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters