我是angular的新手,我从头开始构建这个系统.我编写了以下方法来将GET请求发送到后台的端点.该方法在ngOnInit方法中调用.
public getExistingDrp():Observable<any>{
const url = "http://localhost:2252/api/mldetails/mldropdown?AgID=49&CID=37&intExist=0";
const token = "test-token";
const headers = new HttpHeaders(
{
'Authorization': 'Bearer ' + token
}
);
return this.http.get(url ,{headers: headers})
}
呼叫未到达后台.我已向后台方法添加了断点,当我从postman 发送请求时,它们会被击中.但这个应用程序没有发生任何事情,甚至没有出现错误.浏览器的"网络"选项卡中也没有显示任何内容.控制台给出以下输出.
_Observable {
source: _Observable {
source: _Observable {
source: [_Observable],
operator: [Function (anonymous)]
},
operator: [Function (anonymous)]
},
operator: [Function (anonymous)]
}
我的app. modules.ts如下
import { NgModule } from '@angular/core';
import {
BrowserModule,
provideClientHydration,
} from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import { SidebarComponent } from './components/sidebar/sidebar.component';
import { TransferMLOComponent } from './pages/transfer-mlo/transfer-mlo.component';
import { MLOcomponentsComponent } from './pages/existing-mlodetails/allMLOdetails/mlocomponents/mlocomponents.component';
import { MLOdetailsNavbarComponent } from './pages/existing-mlodetails/mlodetails-navbar/mlodetails-navbar.component';
import { MLOtarrifComponent } from './pages/existing-mlodetails/allMLOdetails/mlotarrif/mlotarrif.component';
import { MLOlocationsComponent } from './pages/existing-mlodetails/allMLOdetails/mlolocations/mlolocations.component';
import { MLOdamagesComponent } from './pages/existing-mlodetails/allMLOdetails/mlodamages/mlodamages.component';
import { MLOrepairComponent } from './pages/existing-mlodetails/allMLOdetails/mlorepair/mlorepair.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { provideHttpClient, withFetch, HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
AppComponent,
NavbarComponent,
SidebarComponent,
TransferMLOComponent,
MLOcomponentsComponent,
MLOdetailsNavbarComponent,
MLOtarrifComponent,
MLOlocationsComponent,
MLOdamagesComponent,
MLOrepairComponent,
],
imports: [BrowserModule, AppRoutingModule, NgbModule, HttpClientModule],
providers: [provideClientHydration(), provideHttpClient(withFetch())],
bootstrap: [AppComponent],
})
export class AppModule {}
我错过了什么吗?我做错了什么吗?