Gathering detailed insights and metrics for ngx-fragments
Gathering detailed insights and metrics for ngx-fragments
Gathering detailed insights and metrics for ngx-fragments
Gathering detailed insights and metrics for ngx-fragments
Extensible module for easy creation of URL based modals, pop-ups and asides
npm install ngx-fragments
Typescript
Module System
Node Version
NPM Version
TypeScript (72.14%)
HTML (23.7%)
JavaScript (2.43%)
SCSS (1.73%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
89 Commits
1 Watchers
2 Branches
1 Contributors
Updated on Aug 22, 2021
Latest Version
1.0.2
Package Id
ngx-fragments@1.0.2
Unpacked Size
218.14 kB
Size
51.23 kB
File Count
34
NPM Version
6.14.14
Node Version
12.22.5
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
3
Ever needed a modal, popup or sidenav that worked based on the URL?
This module takes care of that!
This module does NOT provide the implementation of above mentioned use cases.
1npm install ngx-fragments
The container component is basically the component you want to render your child components content.
Since this module does not provide any container components, we have to provide it to the module.
An example modal container component could look like this:
1import { Component } from '@angular/core'; 2import { FragmentOutletComponent } from 'ngx-fragments'; 3 4@Component({ 5 styles: [` 6 :host { 7 position: relative; 8 display: block; 9 } 10 11 /* The Modal (background) */ 12 .modal { 13 display: block; 14 position: fixed; 15 z-index: 9999; 16 left: 0; 17 top: 0; 18 width: 100%; 19 height: 100%; 20 overflow: auto; 21 } 22 23 .modal-content { 24 margin: 15% auto; 25 padding: 20px; 26 border: 1px solid #888; 27 width: 80%; 28 } 29 30 .close { 31 color: #aaa; 32 float: right; 33 font-size: 28px; 34 font-weight: bold; 35 } 36`], 37 template: ` 38 39 <div class="modal" (click)="outerClick($event)"> 40 41 <div class="modal-content"> 42 <span class="close" (click)="outlet.close()">×</span> 43 <ng-content></ng-content> 44 </div> 45 46 </div> 47 48 ` 49}) 50export class MyCustomModalContainerComponent { 51 constructor(public outlet: FragmentOutletComponent) { 52 } 53 54 public outerClick(event: any): void { 55 event.stopPropagation(); 56 if (event.target.className === 'modal') { 57 this.outlet.close(); 58 } 59 } 60} 61 62
By injecting the FragmentOutletComponent
we have access to the close
function.
Now that we have a container, we will create a component which we want to show inside the container.
For this we will create a simple GreeterModalComponent
. This component will display the value of the queryParameter as greeting.
1import { Component } from '@angular/core'; 2import { FragmentOutletBase } from 'ngx-fragments'; 3 4@Component({ 5 styles: [ 6 `.greeting { 7 font-size: 1.5rem; 8 color: cornflowerblue; 9 text-shadow: #333333; 10 } 11 `, 12 ], 13 template: ` 14 <div class="greeting"> 15 Greeting: {{ whenQueryParamValueChanged$ | async }} 16 </div> 17 `, 18}) 19export class GreeterModalComponent extends FragmentOutletBase { 20 constructor() { 21 super(); 22 } 23}
Notice that we extend FragmentOutletBase
class. This class provides the following observables we can subscribe to.
Property | Description |
---|---|
whenClosed$ | Event on close |
whenQueryParamValueChanged$ | Event on query param value changed |
queryParamValue | Initial query param value |
The configuration object is a dictionary of Fragment
where each key can have his own containerComponent
and entries
list consisting out of FragmentEntry
objects
1export interface Fragment { 2 containerComponent: Type<any>; 3 entries: FragmentEntry[]; 4}
Property | Description |
---|---|
containerComponent | Angular component we want to use as container |
entries | List of FragmentEntry objects |
1export interface FragmentEntry { 2 key: string; 3 type: Type<T>; 4 priority?: number; 5}
Property | Description |
---|---|
key | The query parameter key to use to display this fragment |
type | The component to render inside the container |
priority (optional) | Useful if you want to control which fragment should always be on top |
1const configuration = { 2 modal: { 3 containerComponent: MyCustomModalContainerComponent, 4 entries: [ 5 { 6 key: 'greeter', 7 type: GreeterModalComponent, 8 }, 9 ], 10 } 11}
Finally, pass the configuration to the forRoot
method in your AppModule.
1 2@NgModule({ 3 imports: [ 4 NgxFragmentsModule.forRoot(configuration) 5 ] 6})
Or use forFeature
for lazy loaded modules
1// In AppModule 2@NgModule({ 3 imports: [ 4 NgxFragmentsModule.forRoot() // --> configuration object is optional here 5 ] 6}) 7 8// In Feature Module 9@NgModule({ 10 imports: [ 11 NgxFragmentsModule.forFeature(configuration) // --> configuration is REQUIRED for lazy modules 12 ] 13})
To test the working, we have to navigate to the route we defined.
Since our greeter modal is part of the modal
parent object, the key greeter
will automatically get prefixed with modal:
to avoid query parameter collisions.
1 <a [routerLink]="[]" [queryParams]="{'modal:greeter': 'Hello from year 2021!'}" queryParamsHandling="merge">open greeter</a>
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
101 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More