我想创建一个扩展Angular路由器的RouterUtilities类。该应用程序可以正常工作并编译,但是ng build --prod
返回以下错误:
ERROR in : Can't resolve all parameters for RouterUtilities in .../utils/router/router-utilities.ts: (?, [object Object], [object Object], [object Object], [object Object], [object Object],
[object Object], ?).
router-utilities.ts
import { Compiler, Injectable, Injector, NgModuleFactoryLoader, Type } from '@angular/core';
import { Location } from '@angular/common';
import { Router, UrlSerializer, ChildrenOutletContexts, Routes } from '@angular/router';
import { formatPattern } from 'url-matcher';
import { Dictionary } from '../../../shared/interfaces/common.interface';
@Injectable()
export class RouterUtilities extends Router {
constructor(rootComponentType: Type<any> | null,
urlSerializer: UrlSerializer,
rootContexts: ChildrenOutletContexts,
location: Location,
injector: Injector,
loader: NgModuleFactoryLoader,
compiler: Compiler,
config: Routes) {
super(rootComponentType, urlSerializer, rootContexts, location, injector, loader, compiler, config);
}
static getAbsoluteRoute(routePath: string, params: Dictionary<string> = {}): string {
return 'something';
}
}
你知道为什么会发生吗?
答案 0 :(得分:0)
使用--prod
构建时有所不同。 Compiler
仅在即时(JIT)编译中可用,并且--prod
开关启用提前(AOT)编译。因此,当angular尝试将服务编译到工厂时,找不到Compiler
依赖项。
也许这个long github discussion会以某种方式帮助您。
答案 1 :(得分:0)
解决方案是将路由器包括在以下部门中:
providers: [
{
provide: RouterUtilities,
useClass: RouterUtilities,
deps: [Router]
}
]