import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from "@angular/Router" import { Injectable,Inject, OnDestroy } from "@angular/core"; import { HttpClient } from "@angular/Common/http"; import { Observable, Subject } from "rxjs"; import { DyCommon } from "../Common"; import { ObjectService } from "./ObjectService"; @Injectable() export class InventoryItemResolver implements Resolve,OnDestroy{ private http: HttpClient; constructor(@Inject(HttpClient) _http: HttpClient, @Inject(ObjectService) os: ObjectService) { this.http = _http; this.objectService = os; } public objectService: ObjectService; private ngUnsubscribe: Subject = new Subject(); ngOnDestroy(): any { this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); } resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): any | Observable | Promise { console.log(route); var promise = new Promise((fres, rej) => { if (route.params["id"] == "" || route.params["id"] == undefined) { DyCommon.newGuid().then((id) => { var cont = { id: id, productCategory: {}, vendor: {},active:true }; fres(cont); }) return; } this.objectService.getObject("InventoryItem",route.params["id"]).takeUntil(this.ngUnsubscribe).subscribe(res => { var mod: any = res; // res.contact.recordTypeId = res.contact.recordTypeId.split(","); fres(mod) }); }) return promise; } }