打开应用程序后,它会打开登录页面。 一旦单击登录按钮。 http请求成功完成,但在到达导航时会出现以浏览此错误
NAVIGATE
main.ae4b78b1d85092fcf459.js:1 ERROR Error: Uncaught (in promise): Error:
StaticInjectorError[l -> e]:
StaticInjectorError(Platform: core)[l -> e]:
NullInjectorError: No provider for e!
Error: StaticInjectorError[l -> e]:
StaticInjectorError(Platform: core)[l -> e]:
NullInjectorError: No provider for e!
UNTIL console.log(“ NAVIGATE”);在抛出错误之后,它仍然可以正常工作。无法解决问题。尝试了所有导航方式,但出现错误。 HTTP请求成功完成。相反,此代码在正常的调试版本中可以正常工作。但是我尝试使用--prod或--release。 使用以下代码。发生此问题的行后已添加注释:
this.auth.login(form)
.subscribe(res => {
console.log('res',res,res._body);
res=JSON.parse(res._body);
console.log('Jres',res);
if (res.token)
{
this.storage.set('auth-token', res.token).then(()=>{
this.auth.checkToken()
});
this.storage.set('user', res.user).then(()=>{
this.auth.checkToken()
});
this.globalService.user=res.user;
this.globalService.auth_token=res.token;
console.log("NAVIGATE"); // <------UNTIL HERE IT WORKS FINE BUT AFTER THIS IT THROWS ERROR . Cant get the issue. Tried all the ways to navigate but the error comes.
//this.router.navigateByUrl('/map-all-location');
this.navCtrl.navigateRoot('/map-all-location');
import {GlobalService} from '../services/global.service';
import { HttpClient,HttpParams,HttpHeaders } from '@angular/common/http';
import { Http } from '@angular/http';
constructor(private storage: Storage
, private plt: Platform
, private global: GlobalService
, private http: HttpClient) {
this.plt.ready().then(() => {
this.checkToken();
});
}
login (data): Observable<any> {
let headers = new HttpHeaders();
return this.http
.post<any>(this.global.apiUrl + 'api/users/login/', data)
.pipe(
tap(_ => this.log('login')),
catchError(this.handleError('login', []))
);
}
以下是app.module.ts的代码:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { AuthenticationService} from './services/authentication.service';
import {GlobalService} from './services/global.service';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { IonicStorageModule } from '@ionic/storage';
import { ReactiveFormsModule} from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { HttpModule } from '@angular/http';
import { FullnessPage } from './page/fullness/fullness.page';
import { SignupPage } from './page/signup/signup.page';
import { CollectionDetailPage } from './page/collection-detail/collection-detail.page';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
declarations: [AppComponent,FullnessPage,SignupPage,CollectionDetailPage],
entryComponents: [FullnessPage,SignupPage ,CollectionDetailPage],
imports: [BrowserModule
, IonicModule.forRoot()
, AppRoutingModule
,IonicStorageModule.forRoot()
,ReactiveFormsModule
,HttpModule
,HttpClientModule,
],
providers: [AuthenticationService,GlobalService,
FileTransfer,
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
我不明白是什么原因造成的。最初,我尝试更改http,但是它对请求没有任何影响,其他所有东西都可以正常工作。主要问题在导航部分。