本文介绍了angular2 rc1:RouterOutletMap 没有提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个组件中创建了一个子组件.我还创建了相应的路线.现在,在我这样做之后,最初由 angular-cli 创建的测试失败了:

I created a subcomponent within a component. I also created the according routes. Now after I did this, the test that was originally created by angular-cli fails with:

没有 RouterOutletMap 的提供者!

此错误消息是否有任何一般原因?我总是可以发布整个组件源代码,但这在这一点上似乎有点矫枉过正:-)

Is there any general reason for this error-message? I could always post the whole component-sourcecode, but that seems overkill at this point :-)

我正在使用新路由器 (rc1)

I am using the new router (rc1)

推荐答案

确保你在你的主 AppComponent 中使用了以下 5 点-

Make sure you have used following 5 points in your main AppComponent-

import { ROUTER_PROVIDERS, Routes, ROUTER_DIRECTIVES, Router } from '@angular/router';


directives: [ROUTER_DIRECTIVES],


providers: [ROUTER_PROVIDERS]


@Routes([
    { path: '/', component: WelcomeComponent },


export class AppComponent {
        constructor(private router: Router) {}
}

在 index.html 中,您有

And in index.html, you have <base href="/">

<!DOCTYPE html>
<html>

<head lang="en">
    <base href="/">
    <title>Acme Product Management</title>

看看这是否有帮助.

这篇关于angular2 rc1:RouterOutletMap 没有提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 10:58