mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-13 14:23:02 -05:00
docs(context-outlet-typed): update content
This commit is contained in:
@@ -16,30 +16,34 @@ sidebar:
|
|||||||
|
|
||||||
## Information
|
## Information
|
||||||
|
|
||||||
Angular offer the static function [`ngTemplateContextGuard`](https://angular.io/guide/structural-directives#typing-the-directives-context) to strongly type structural directive.
|
You can improve template type checking for custom directives by adding template guard properties to your directive definition. Angular offer the static function [`ngTemplateContextGuard`](https://angular.io/guide/structural-directives#typing-the-directives-context) to strongly type structural directives.
|
||||||
|
|
||||||
However the context of **NgTemplateOutlet** type is **Object**. But with the help of the above guard, we can improve that behavior.
|
However the context of **NgTemplateOutlet** type is **Object**. But with the help of the above guard, we can improve that behavior.
|
||||||
|
|
||||||
|
If you’re not very familiar with `ngTemplateOutlet`, check out this article.
|
||||||
|
|
||||||
|
- [NgTemplateOutlet Type Checking](https://medium.com/@thomas.laforge/ngtemplateoutlet-type-checking-5d2dcb07a2c6)
|
||||||
|
|
||||||
## Statement
|
## Statement
|
||||||
|
|
||||||
In this exercise, we want to learn how to strongly type our ng-template in our AppComponent.
|
In this exercise we want to learn how to strongly type our `ng-template` in our `AppComponent`.
|
||||||
|
|
||||||
This exercise has two levels of complexity.
|
This exercise has two levels of complexity.
|
||||||
|
|
||||||
### Level 1: known Interface
|
### Level 1: Known Interface
|
||||||
|
|
||||||
Currently we have the following piece of code.
|
Currently we have the following piece of code.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
As we can see, name is of type "any". We want to infer the correct type.
|
As we can see `name` is of type `any`. We want to infer the correct type using a custom directive `PersonDirective`.
|
||||||
|
|
||||||
### Level 2: generic Interface
|
### Level 2: Generic Interface
|
||||||
|
|
||||||
Currently we have the following piece of code.
|
Currently we have the following piece of code.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
As we can see, student is of type "any". We want to infer the correct type.
|
As we can see `student` is of type `any`. We want to infer the correct type using a custom directive `ListDirective`.
|
||||||
|
|
||||||
But in this part, we can pass to ListComponent, a list of **any object**. And we still want the correct type to be inferred.
|
But in this part, we want to pass a list of **any object** to `ListComponent`. And we still want the correct type to be inferred.
|
||||||
|
|||||||
Reference in New Issue
Block a user