2017-08-14 33 views
1

在瀏覽器控制檯中查看例外情況。在Angular2中獲取異常EXCEPTION:沒有PlatformLocation的提供者?

EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in :0:0 
ORIGINAL EXCEPTION: No provider for PlatformLocation! 
ORIGINAL STACKTRACE: 
Error: DI Exception 
    at NoProviderError.BaseException [as constructor] (http://localhost:3000/lib/@angular/core/core.umd.js:3776:27) 
    at NoProviderError.AbstractProviderError [as constructor] (http://localhost:3000/lib/@angular/core/core.umd.js:4307:20) 
    at new NoProviderError (http://localhost:3000/lib/@angular/core/core.umd.js:4342:20) 
    at ReflectiveInjector_._throwOrNull (http://localhost:3000/lib/@angular/core/core.umd.js:5794:23) 
    at ReflectiveInjector_._getByKeyDefault (http://localhost:3000/lib/@angular/core/core.umd.js:5822:29) 
    at ReflectiveInjector_._getByKey (http://localhost:3000/lib/@angular/core/core.umd.js:5785:29) 
    at ReflectiveInjector_.get (http://localhost:3000/lib/@angular/core/core.umd.js:5594:25) 
    at _View_WalletPlus_Host0.createInternal (WalletPlus_Host.template.js:38:83) 
    at _View_WalletPlus_Host0.AppView.create (http://localhost:3000/lib/@angular/core/core.umd.js:9862:25) 
    at _View_WalletPlus_Host0.DebugAppView.create (http://localhost:3000/lib/@angular/core/core.umd.js:10054:48) 
ERROR CONTEXT: 
[object Object] 

請幫忙解決這個問題。不完全理解什麼是問題。

下面是index.ts我引導我的應用程序。

import {bootstrap} from "@angular/platform-browser-dynamic"; 
import {enableProdMode,provide} from "@angular/core"; 
import {ROUTER_PROVIDERS} from "@angular/router"; 
import {HTTP_PROVIDERS} from "@angular/http"; 
import {MyAppComponent} from "./components/MyApp.component"; 
import {SimpleExpiry} from 'ng2-idle/simpleexpiry'; 

import {APP_BASE_HREF, LocationStrategy, HashLocationStrategy} from "@angular/common"; 

enableProdMode(); 
bootstrap(<any>MyAppComponent, [ROUTER_PROVIDERS, HTTP_PROVIDERS,SimpleExpiry, 
provide(APP_BASE_HREF, { useValue: "/" }), 
provide(LocationStrategy, { useClass: HashLocationStrategy })]); 

回答

0

你必須失去NativeScriptRouterModule內進口的main.ts文件。

import { NativeScriptRouterModule } from "nativescript-angular/router"; 
import { NativeScriptFormsModule } from "nativescript-angular/forms"; 

@NgModule({ 
    declarations: [ 
     AppComponent, 
     routableComponents, 
    ], 
    bootstrap: [AppComponent], 
    imports: [ 
     NativeScriptModule, 
     NativeScriptFormsModule, 
     NativeScriptRouterModule, 
     NativeScriptRouterModule.forRoot(routes), 
    ], 
}) 
+0

我使用角度2.0.0-rc.1版本(發佈候選版本)不穩定的版本。 –

相關問題