DEV Community

loizenai
loizenai

Posted on

Django + Angular 6 example | Django Rest Framework + MySQL CRUD example – Part 3: Angular Client

https://ozenero.com/django-angular-6-example-django-rest-framework-angular-crud-mysql-example-part-3-angular-client

Django + Angular 6 example | Django Rest Framework + MySQL CRUD example – Part 3: Angular Client

This tutorial is part 3 of Django-Angular-MySQL series. Today, we will create Angular Client to make HTTP request & receive response from Django Server.

>> Part 1: Overview
>> Part 2: Django Server

Video

Angular Client Overview

Goal

The image below shows overview about Angular Components that we will create:

django-angular-6-django-rest-api-mysql-angular-client-architecture

Project Structure

django-angular-6-django-rest-api-mysql-angular-project-structure

We have:
- 4 components: customers-list, customer-details, create-customer, search-customer.
- 3 modules: FormsModule, HttpClientModule, AppRoutingModule.
- customer.ts: class Customer (id, firstName, lastName)
- customer.service.ts: Service for Http Client methods
- app-routing.module.ts: Routing configuration

Setup Angular Project

Create Angular Project

Run command: ng new AngularDjango.

Create Service & Components

On Project folder, run commands below:
- ng g s customer
- ng g c create-customer
- ng g c customer-details
- ng g c customers-list
- ng g c search-customers
On each Component selector, delete app- prefix, then change tslint.json rules - "component-selector" to false.

Implement Angular Client App

Data Model

Create new file named customer.ts:

export class Customer {
    id: number;
    name: string;
    age: number;
    active: boolean;
}
Data Service

More at:

Django + Angular 6 example | Django Rest Framework + MySQL CRUD example – Part 3: Angular Client

https://ozenero.com/django-angular-6-example-django-rest-framework-angular-crud-mysql-example-part-3-angular-client

Top comments (0)