@tilde-nlp/ngx-strapi
v6.0.2
Published
Simple library for communicating with Strapi CMS. Functions are mostly generic and library should not know nothing specific about business logic. It should implement only common methods that can be used in all projects that use strapi.
Downloads
99
Keywords
Readme
NgxStrapi
Simple library for communicating with Strapi CMS. Functions are mostly generic and library should not know nothing specific about business logic. It should implement only common methods that can be used in all projects that use strapi.
StrapiApiService
Service for http communication with strapi.
StrapiService
Service for easier implementation with localizations for strapi single types and ngx-translate library. It listens to language changes and reads specific locale for active single types. Type is active when id from api is passed to activateSingleType method and it has not been deactivated. This kind of active/not active mechanism is implemented because you don't need to read all types any time when language changes because it is waste of resources. Type should be activated when strapi content is rendered (at components onInit method) and deactivated when it gets destroyed.
StrapiSubscriptionService
Service made for complex type strapi models. Use subscribeActivity
method to subscribe for starpi service. subscribeActivity
method returns Observable<T | null>
which can be subscribed for initial values as well as language.
Usage example:
{ ... }
constructor(public readonly strapiService: StarpiMenuService) {}
// Create `Observable` to be subscribed
const responseObs: Observable<T> = this.strapiSubscription
.subscribeActivity<T>(CollectionTypes.MY_DATA, null);
// Subscribe for data
responseObs.subscribe((data: T) => this.myData = data)
To unsubscribe for value changes call unsubscribe
method by providing the same input parameters.
StrapiHtmlComponent
Component meant for displaying content from strapi rich text in html format. Component modifies response html to make angular function as proper SPA.
- It finds all
<a>
tags in html string and adds custom function on links click event. This function checks if links href includes origin href - if it does, it means that the route is inner route for application so it prevents default event on click and uses angular router to navigate to route without reloading app. If the link is from outside, proper navigation takes place. - Finds all
<img>
tags, loops through them and modifies image source. Window.location.origin gets replaced with strapi api url, so that images are loaded properly. By default, strapi returns image url without base url and angular automatically searches for image on its domain, not strapi api.
ProductPageBuilderComponent
Component is made for easy custom page creation with strapi. This allows for non-developers to create content in project. It also subscribes for language change and looks at strapi for translations.
Example
Add wildcard route with this component
{
path: '**',
component: ProductPageBuilderComponent
}
When no other route is found, angular creates instance of this component, who then looks in strapi for Custom-page type with specified route. If it is not found, it redirects to provided route for input parameter @Input() redirectRoute = "";
.