taiga-family/polymorpheus
关于
Polymorpheus 是一个用于 Angular 多态模板的小型库。
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Polymorpheus
Polymorpheus is a tiny library for polymorphic templates in Angular.
It is 1 KB gzip, dependency free and allows you to make pretty cool things.
What does it do?
It abstracts over different ways of view customization in Angular with one simple structural directive:
<ng-container *polymorpheusOutlet="content as text; context: context">{{text}}</ng-container>
Content accepts:
- primitives like
numberorstring - functions that take
contextas argument and return a primitive - templates that get instantiated with given
context - components that would get
contextinjected through DI
Context is optional when you need your content to adapt to the situation
How to use it?
Typical use case would be a component that accepts visual customization and defines context by itself. Say a menu list where you can configure how each item should look like by passing a template. And context would be item itself and, for example, whether it is focused or not.
Please see extensive demo (wait for packages to install and run
npm start).
You can also read about this concept in detail.
Accessing context in dynamic component
If you use component content you can inject context with POLYMORPHEUS_CONTEXT token or injectContext helper.
Important: this object is live so if you change it, your component view will be updated as well automatically.
import {injectContext} from '@taiga-ui/polymorpheus';
@Component({
template: '{{ context.active }}', // <-- this will automatically update
})
export class MyComponent {
protected readonly context = injectContext<{active: boolean}>();
}
Alternatively, inputs can be used and will be synced with according context keys:
import {input} from '@angular/core';
@Component({
template: '{{ active() }}',
})
export class MyComponent {
// Will be automatically updated by context.active changes
protected readonly active = input(false);
}
Adding type to template context
You can use polymorpheus directive to add type to template context:
readonly context!: { $implicit: number };
<ng-template
#template="polymorpheus"
[polymorpheus]="context"
let-item
>
{{ item.toFixed(2) }} <-- type 'number'
</ng-template>
Core team
![]() Alex Inkin |
![]() Roman Sedov |
ng-polymorpheus is a part of Taiga UI libraries family which is backed and used by a large enterprise. This means you can rely on timely support and continuous development.
探索相关项目
加载中…

