ContextStrategy

ContextStrategy is an abstract class exposed by @abp/ng.core package. There are three context strategies extending it: ComponentContextStrategy, TemplateContextStrategy, and NoContextStrategy. Implementing the same methods and properties, all of these strategies help you define how projected content will get their context.

ComponentContextStrategy

ComponentContextStrategy is a class that extends ContextStrategy. It lets you pass context to a projected component.

constructor

constructor(public context: Partial<InferredInstanceOf<T>>) {}
JavaScript
  • T refers to component type here, i.e. Type<C>.
  • InferredInstanceOf is a utility type exposed by @abp/ng.core package. It infers component shape.
  • context will be mapped to properties of the projected component.

setContext

setContext(componentRef: ComponentRef<InferredInstanceOf<T>>): Partial<InferredInstanceOf<T>>
JavaScript

This method maps each prop of the context to the component property with the same name and calls change detection. It returns the context after mapping.

TemplateContextStrategy

TemplateContextStrategy is a class that extends ContextStrategy. It lets you pass context to a projected template.

constructor

constructor(public context: Partial<InferredContextOf<T>>) {}
JavaScript
  • T refers to template context type here, i.e. TemplateRef<C>.
  • InferredContextOf is a utility type exposed by @abp/ng.core package. It infers context shape.
  • context will be mapped to properties of the projected template.

setContext

setContext(): Partial<InferredContextOf<T>>
JavaScript

This method does nothing and only returns the context, because template context is not mapped but passed in as parameter to createEmbeddedView method.

NoContextStrategy

NoContextStrategy is a class that extends ContextStrategy. It lets you skip passing any context to projected content.

constructor

constructor()
JavaScript

Unlike other context strategies, NoContextStrategy contructor takes no parameters.

setContext

setContext(): undefined
JavaScript

Since there is no context, this method gets no parameters and will return undefined.

Predefined Context Strategies

Predefined context strategies are accessible via CONTEXT_STRATEGY constant.

None

CONTEXT_STRATEGY.None()
JavaScript

This strategy will not pass any context to the projected content.

Component

CONTEXT_STRATEGY.Component(context: Partial<InferredContextOf<T>>)
JavaScript

This strategy will help you pass the given context to the projected component.

Template

CONTEXT_STRATEGY.Template(context: Partial<InferredContextOf<T>>)
JavaScript

This strategy will help you pass the given context to the projected template.

See Also

Contributors


Last updated: July 31, 2024 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

Community Talks

Deep Dive #1: Identity&Account Modules

17 Apr, 17:00
Online
Watch the Event
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book