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:
This is what my routing file looks like:
and finally my package.json file:
Could some please explain why this is happening and what the resolution is? Thank you.
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
Most helpful comment
Hi @Sulman633,
Perhaps the problem is due missing
NativeScriptRouterModuleinsideimportsthe inmain.tsfile. You could review the example below.main.tsI hope this will help.