apstorydnn-navigation-angular
Version:
[](https://apstory.visualstudio.com/ApStory/_build/latest?definitionId=25)
106 lines (101 loc) • 3.69 kB
JavaScript
import * as i1 from '@angular/common';
import * as i0 from '@angular/core';
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
class ApstorydnnNavigationService {
constructor(componentFactory, location) {
this.componentFactory = componentFactory;
this.location = location;
this.navSubject = new Subject();
this.paramSubject = new Subject();
this.navStack = [];
this.params = {};
}
setUrl(url) {
location.href = url;
}
getUrlParam(paramName) {
const path = this.location.path(false);
const queryString = path.substr(path.indexOf('?') + 1);
const urlParameters = new URLSearchParams(queryString);
return urlParameters.get(paramName);
}
clearUrlParams() {
this.location.replaceState('/', '');
}
getNavigationEvent() {
return this.navSubject.asObservable();
}
getParameterEvent() {
return this.paramSubject.asObservable();
}
setComponent(type) {
if (this.componentRef) {
this.componentRef.destroy();
}
const factory = this.componentFactory.resolveComponentFactory(type);
this.componentRef = this.componentHolder.createComponent(factory);
}
setup(navHolder) {
this.componentHolder = navHolder;
}
setParam(key, value) {
this.params[key] = value;
this.paramSubject.next(key);
}
getParam(key) {
return this.params[key];
}
push(page) {
if (this.prevPage) {
this.navStack.push(this.prevPage);
}
this.setComponent(page);
this.prevPage = page;
this.navSubject.next(this.componentRef);
}
canPop() {
return this.navStack.length > 0;
}
popTo(screen) {
while (typeof (screen) != typeof (this.prevPage)) {
if (this.canPop()) {
this.prevPage = this.navStack.pop();
}
}
this.setComponent(this.prevPage);
this.navSubject.next(this.componentRef);
}
popBack(nr) {
for (let i = 0; i < nr; i++) {
if (this.canPop()) {
this.prevPage = this.navStack.pop();
}
}
this.setComponent(this.prevPage);
this.navSubject.next(this.componentRef);
}
pop() {
if (this.canPop()) {
this.prevPage = this.navStack.pop();
this.setComponent(this.prevPage);
this.navSubject.next(this.componentRef);
}
}
}
/** @nocollapse */ ApstorydnnNavigationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: ApstorydnnNavigationService, deps: [{ token: i0.ComponentFactoryResolver }, { token: i1.Location }], target: i0.ɵɵFactoryTarget.Injectable });
/** @nocollapse */ ApstorydnnNavigationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: ApstorydnnNavigationService, providedIn: 'root' });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: ApstorydnnNavigationService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root'
}]
}], ctorParameters: function () { return [{ type: i0.ComponentFactoryResolver }, { type: i1.Location }]; } });
/*
* Public API Surface of apstorydnn-navigation
*/
/**
* Generated bundle index. Do not edit.
*/
export { ApstorydnnNavigationService };
//# sourceMappingURL=apstorydnn-navigation-angular.mjs.map