File

projects/netgrif-components-core/src/lib/navigation/group-navigation-component-resolver/abstract-group-navigation-component-resolver.component.ts

Implements

OnInit OnDestroy

Metadata

selector ncc-abstract-group-nagiation-resolver

Index

Properties
Methods

Constructor

Protected constructor(_componentResolverService: GroupNavigationComponentResolverService, _parentInjector: Injector, _activatedRoute: ActivatedRoute, _router: Router, _log: LoggerService)
Parameters :
Name Type Optional
_componentResolverService GroupNavigationComponentResolverService No
_parentInjector Injector No
_activatedRoute ActivatedRoute No
_router Router No
_log LoggerService No

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Protected resolveComponent
resolveComponent()
Returns : void

Properties

Public errored
Default value : false
Public initialized
Default value : false
Public portal
Type : ComponentPortal<any>
import {GroupNavigationComponentResolverService} from './group-navigation-component-resolver.service';
import {Component, Injector, OnDestroy, OnInit} from '@angular/core';
import {ComponentPortal} from '@angular/cdk/portal';
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
import {GroupNavigationConstants} from '../model/group-navigation-constants';
import {Subscription} from 'rxjs';
import {filter} from 'rxjs/operators';
import {destroySubscription} from '../../utility/destroy-subscription';
import {LoggerService} from '../../logger/services/logger.service';

@Component({
    selector: 'ncc-abstract-group-nagiation-resolver',
    template: ''
})
export abstract class AbstractGroupNavigationComponentResolverComponent implements OnInit, OnDestroy {

    public portal: ComponentPortal<any>;
    public initialized = false;
    public errored = false;

    private _portalSub: Subscription;
    private _routerSub: Subscription;

    protected constructor(protected _componentResolverService: GroupNavigationComponentResolverService,
                          protected _parentInjector: Injector,
                          protected _activatedRoute: ActivatedRoute,
                          protected _router: Router,
                          protected _log: LoggerService) {
    }

    ngOnInit(): void {
        this.resolveComponent();
        this._routerSub = this._router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(() => {
            this.resolveComponent();
        });
    }

    ngOnDestroy(): void {
        destroySubscription(this._portalSub);
        destroySubscription(this._routerSub);
    }

    protected resolveComponent(): void {
        this.initialized = false;
        this._portalSub = this._componentResolverService.createResolvedViewComponentPortal(
            this._activatedRoute.snapshot.paramMap.get(GroupNavigationConstants.GROUP_NAVIGATION_ROUTER_PARAM),
            this._parentInjector
        ).subscribe(portal => {
            this.portal = portal;
            this.initialized = true;
        }, error => {
            this._log.error(error);
            this.errored = true;
        });
    }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""