Skip to content

Commit 226a8da

Browse files
committed
feat: add known directive
1 parent 4bb1655 commit 226a8da

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { PersonDirective } from './person.directive';
2+
3+
describe('PersonDirective', () => {
4+
it('should create an instance', () => {
5+
const directive = new PersonDirective();
6+
expect(directive).toBeTruthy();
7+
});
8+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Directive, inject, TemplateRef } from '@angular/core';
2+
3+
interface PersonTemplateContext {
4+
$implicit: string;
5+
age: number;
6+
}
7+
8+
@Directive({
9+
selector: 'ng-template[personTemplate]',
10+
})
11+
export class PersonDirective {
12+
private readonly tpl = inject<TemplateRef<PersonTemplateContext>>;
13+
14+
static ngTemplateContextGuard(
15+
_dir: PersonDirective,
16+
ctx: unknown,
17+
): ctx is PersonTemplateContext {
18+
return true;
19+
}
20+
}

0 commit comments

Comments
 (0)