我在 Angular-CLI 和 .NET Core 2.0 中使用 Angular 5.2.2(打字稿)。
我正在尝试向我的应用程序动态添加其他路由。
这个想法是我从服务器动态获取我的路由,该服务器检查哪些模块应该可供用户使用。但我似乎无法获得可用的路线。
我尝试使用添加它们,RouterModule.forRoot
但这不起作用。
我试过使用,Router.resetConfig
但我似乎无法让它工作。我尝试使用依赖注入在我创建的函数中获取它,但我最终得到了循环依赖:
Uncaught Error: Provider parse errors:
Cannot instantiate cyclic dependency! ApplicationRef ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
Run Code Online (Sandbox Code Playgroud)
这是我拥有的一些代码:
app-routing.module.ts
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { Routes, RouterModule, Router } from '@angular/router';
var routes: Routes = [{ path: '', loadChildren: "../app/modules/f2p-dashboard/f2p-dashboard.module#F2PDashboardModule" }];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: [
{
provide: APP_INITIALIZER,
useFactory: AppConfigServiceFactory,
deps: [F2PModuleService, Router ],
multi: true
} …
Run Code Online (Sandbox Code Playgroud) 我将 Angular 5 与 Jasmine 和 Karma 一起使用。我正在尝试测试某个功能是否有效,但我的订阅在单元测试期间没有触发。这导致我的单元测试失败,因为我正在使用 jasmine 的 did 函数。我想让这个单元测试成功。
我已将超时间隔设置为 20 秒,以查看是否只花了一段时间(实际上不应该)。
我也尝试过使用 async 和 fakeasync,但它不会触发。我可以触发订阅吗?
这是我得到的代码:
describe('FilterService', () => {
let service: FilterService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [FilterService]
});
service = TestBed.get(FilterService);
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
});
it("SetItemsToFilterByAndApplyFilters should set ItemsToFilterBy and set the InFilter property", (done: DoneFn) => {
//arrange
let item1: any = new Organisation();
item1.Id = 1;
item1.InFilter = true;
let item2: any = new Organisation();
item1.Id = 2;
item1.InFilter = false;
let …
Run Code Online (Sandbox Code Playgroud)