我在功能模块中声明了一个带有路由模块的组件
import { TestResolverService } from './service/test.resolver.service';
import { MyComponent } from './containers/my-component/mycomponent.component';
const routes: Routes =
[
{
path: '',
component: MyComponent,
resolve: TestResolverService
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class MyRoutingModule { }
TestResolverService在此处的同一模块中定义:
@Injectable({
providedIn: 'root'
})
export class TestResolverService implements Resolve<void>{
constructor() { }
resolve(x, y) {}
}
该模块是从根目录懒加载的:
{path: 'mymodule', loadChildren: () => import('./features/test/mymodule.module').then(m => m.MyModule)}
每当我尝试将resolve
加载到页面时,都会出现以下错误:
ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(PathwaysModule)[TestResolverService_Factory -> TestResolverService_Factory -> TestResolverService_Factory -> TestResolverService_Factory]:
NullInjectorError: No provider for TestResolverService_Factory!
NullInjectorError: R3InjectorError(MyModule)[TestResolverService_Factory -> TestResolverService_Factory -> TestResolverService_Factory -> TestResolverService_Factory]:
NullInjectorError: No provider for TestResolverService_Factory!
我想念什么?没有resolve
的情况下,页面可以正常加载,并且直接从组件导入和调用服务也可以。只有当作为解析器引用时,我才会遇到此问题。
答案 0 :(得分:0)
我能够通过将resolve: TestResolverService
更改为
resolve: { resolver: TestResolverService }
我的解决类型错误。