【问题标题】:Angular2 Can't resolve all parameters for provideLocationStrategyAngular2无法解析provideLocationStrategy的所有参数
【发布时间】:2016-09-28 04:44:16
【问题描述】:

我遵循了 Angular2 的路由教程。但是,我现在遇到了一个我似乎无法修复的奇怪错误:

127.0.0.1/:21 错误:(SystemJS) 无法解析 provideLocationStrategy 的所有参数:(PlatformLocation, ?, Token_ROUTER_CONFIGURATION)。

app.routing.ts

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {MyComponent} from "./myComponent/myComponent.component";

const appRoutes: Routes = [
    { path: '', component: MyComponent},
    { path: '**', component: MyComponent}
];
//
//export const appRoutingProviders: any[] = [
//
//];
//
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { routing, appRoutingProviders } from './app.routing';
import { AppComponent }   from './app.component';
import {MyComponent} from "./myComponent/myComponent.component";

@NgModule({
    imports: [
        BrowserModule,
        routing
    ],
    declarations: [
        AppComponent,
        MyComponent
    ],
    providers: [
        //appRoutingProviders
    ],
    bootstrap: [
        AppComponent
    ]
})
export class AppModule { }

在文档中,他们从 app.routing.ts 导出 appRoutingProviders,但在教程中却没有,所以我将其省略了。结果是一样的,反正它似乎只是一个空数组。

什么可能导致这个错误?

【问题讨论】:

  • index.html 页面上有<base href="/"><router-outlet></router-outlet>

标签: angular angular2-routing


【解决方案1】:

在为此苦苦挣扎了一整天后,发布后 5 分钟我找到了答案。

我清除了我的 System.config 中的映射并重新安装了所有软件包,它工作正常。在不清除映射的情况下重新安装包似乎已经安装了相同包的多个版本,这可能会搞砸。

Angular 很简单,但它周围的一切都让它变得困难。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多