Page Component
ABP provides a component that wraps your content with some built-in components to reduce the amount of code you need to write.
If the template of a component looks as follows, you can utilize the abp-page
component.
Let's look at the following example without abp-page
component.
dashboard.component.ts
Page Parts
PageComponent divides the template shown above into three parts, title
, breadcrumb
, toolbar
. Each can be configured separately. There, also, is an enum exported from the package that describes each part.
Usage
Firstly, you need to import PageModule
from @abp/ng.components/page
as follows:
dashboard.module.ts
And change the template of dashboard.component.ts
to the following:
Inputs
- title:
string
: Will be be rendered withinh1.content-header-title
. If not provided, the parentdiv
will not be rendered - breadcrumb:
boolean
: Determines whether to renderabp-breadcrumb
. Default istrue
. - toolbar:
any
: Will be passed intoabp-page-toolbar
component throughrecord
input. If your page does not containabp-page-toolbar
, you can simply omit this field.
Overriding template
If you need to replace the template of any part, you can use the following sub-components.
You do not have to provide them all. You can just use which one you need to replace. These components have priority over the inputs declared above. If you use these components, you can omit the inputs.
PagePartDirective
PageModule
provides a structural directive that is used internally within PageComponent
and can also be used externally.
PageComponent
employs this directive internally as follows:
It also can take a context input as follows:
Its render strategy can be provided through Angular's Dependency Injection system.
It expects a service through the PAGE_RENDER_STRATEGY
injection token that implements the following interface.
shouldRender
(required): It takes a string input namedtype
and expects aboolean
orObservable<boolean>
in return.onInit
(optional): Will be called when the directive is initiated. Three inputs will be passed into this method.type
: type of the page partinjector
: injector of the directive which could be used to retrieve anything from directive's DI tree.context
: whatever context is available at the initialization phase.
onDestroy
(optional): Will be called when the directive is destroyed. The parameters are the same withonInit
onContextUpdate
(optional): Will be called when the context is updated.change
: changes of thecontext
will be passed through this method.
Let's see everything in action.