如何将 Django Rest Framework Api 与 AngularJS 中的前端集成?

How to integrate Django Rest Framework Api with a front in AngularJS?

这是我第一次接触AngularJS。我想在Angular前面集成api,我的目标只是return一个数据列表,尽可能简单是我的目标。

[link][1] 服务器通信设置 在使用 HttpClient 之前,您需要导入 Angular HttpClientModule。大多数应用程序在根 AppModule 中这样做。

app/app.module.ts (excerpt)


    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { HttpClientModule } from '@angular/common/http';

You can then inject the HttpClient service as a dependency of an application class, as shown in the following ConfigService example.

app/config/config.service.ts (excerpt)

    import { Injectable } from '@angular/core';
    import { HttpClient } from '@angular/common/http';
    
    @Injectable()
    export class ConfigService {
      constructor(private http: HttpClient) { }
    }
    The HttpClient service makes use of observables for all transactions. You must import the RxJS observable and operator symbols that appear in the example snippets. These ConfigService imports are typical.

app/config/config.service.ts (RxJS imports)
content_copy
import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';