angular2 rc1: No provider for RouterOutletMap

送分小仙女□ 提交于 2019-12-12 03:22:23

问题


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:

No provider for 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 :-)

Edit: I am using the new router (rc1)


回答1:


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) {} 
}

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

<!DOCTYPE html>
<html>

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

See if this helps.



来源:https://stackoverflow.com/questions/37675921/angular2-rc1-no-provider-for-routeroutletmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!