问题
The following Nativescript Angular application- demonstrates navigation using <router-outlet></router-outlet>
- but after to ANGULAR "2.0.0-rc.4" and ROUTER "3.0.0-beta.2", the application fails to load.
ERROR thrown:
No provider for Router!
JS: EXCEPTION: Error in ./AppComponent class AppComponent_Host - inline template:0:0 JS: ORIGINAL EXCEPTION: No provider for Router! JS: ORIGINAL STACKTRACE: JS: Error: DI Exception JS: at NoProviderError.BaseException [as constructor] (/data/data/org.nativescript.testapp/files/app/tns_modules/@angular/core/src/facade/exceptions.js:27:23)
回答1:
The current official version of nativescript-angular package depends on RC3 @angular code and will probably wont work well with RC4 (there are some internal changes that will break it). However, you can try using the @next builds of nativescript-angular
that are already migrated to use RC4.
Check here for more info on how to do that.
回答2:
I'm not sure about the actual issue. But I'm guessing, problem is in main.ts.
nativeScriptBootstrap(AppComponent, [AppComponent,HTTP_PROVIDERS,app_globals]);
add APP_ROUTER_PROVIDERS to it. So it will be:
nativeScriptBootstrap(AppComponent, [AppComponent,HTTP_PROVIDERS,app_globals, APP_ROUTER_PROVIDERS]);
来源:https://stackoverflow.com/questions/38522706/nativescript-angular-no-provider-for-router-rc4-router-3-0-0-beta-2