Nativescript-angular: No provider for PlatformLocation!

Created on 3 Oct 2016  路  3Comments  路  Source: NativeScript/nativescript-angular

I am getting the following error while I am trying to implement simple routing:

No provider for PlatformLocation!

Error: No provider for PlatformLocation!
at NoProviderError.Error (native)
at NoProviderError.BaseError as constructor
at NoProviderError.AbstractProviderError as constructor
at new NoProviderError (/data/data/org.nativescript.nightlivefront/files/app/tns_modules/@angular/core/bundles/core.umd.js:1734:20)
at ReflectiveInjector_._throwOrNull (/data/data/org.nativescript.nightlivefront/files/app/tns_modules/@angular/core/bundles/core.umd.js:3331:23)
at ReflectiveInjector_._getByKeyDefault (/data/data/org.nativescript.nightlivefront/files/app/tns_modules/@angular/core/bundles/core.umd.js:3359:29)
at ReflectiveInjector_._getByKey (/data/data/org.nativescript.nightlivefront/files/app/tns_modules/@angular/core/bundles/core.umd.js:3322:29)
at ReflectiveInjector_.get (/data/data/org.nativescript.nightlivefront/files/app/tns_modules/@angular/core/bundles/core.umd.js:3131:25)
at NgModuleInjector.Object.defineProperty.get (AppComponentModule.ngfactory.js:104:119)
at NgModuleInjector.Object.defineProperty.get (AppComponentModule.ngfactory.js:109:84)

This error occurs when I add an array of navigatableComponents to my main.ts declarations, here is a screen shot:
maints

This is what my routing file looks like:
routing

and finally my package.json file:
packagejson

Could some please explain why this is happening and what the resolution is? Thank you.

Most helpful comment

Hi @Sulman633,
Perhaps the problem is due missing NativeScriptRouterModule inside imports the in main.ts file. You could review the example below.
main.ts

import { platformNativeScriptDynamic, NativeScriptModule } from "nativescript-angular/platform";
import { routes, routableComponents } from "./app.routes";
import { AppComponent } from "./app.component";
import { NgModule } from "@angular/core";
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),
    ],
})
class AppComponentModule { }

platformNativeScriptDynamic().bootstrapModule(AppComponentModule);

I hope this will help.

All 3 comments

Hi @Sulman633,
Perhaps the problem is due missing NativeScriptRouterModule inside imports the in main.ts file. You could review the example below.
main.ts

import { platformNativeScriptDynamic, NativeScriptModule } from "nativescript-angular/platform";
import { routes, routableComponents } from "./app.routes";
import { AppComponent } from "./app.component";
import { NgModule } from "@angular/core";
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),
    ],
})
class AppComponentModule { }

platformNativeScriptDynamic().bootstrapModule(AppComponentModule);

I hope this will help.

@tsonevn Thank you, very much that worked!

Same thing, had to import the NativeScriptRouterModule clean also
Thanks @tsonevn

Was this page helpful?
0 / 5 - 0 ratings