In this tutorial, we will walk through the process of creating a CRUD (Create, Read, Update, Delete) application using Angular 15, Material UI, and JSON-server. This tutorial will guide you step by step on how to set up the project, create the necessary components, and implement CRUD operations.
Prerequisites:
- Basic knowledge of Angular, HTML, CSS, and TypeScript.
- Node.js and npm installed on your machine.
- Angular CLI installed globally.
Step 1: Set up the project
-
Create a new Angular project by running the following command in your terminal:
ng new angular-crud-material-ui
-
Change directory to the newly created project:
cd angular-crud-material-ui
-
Install Material UI and Angular Material dependencies:
ng add @angular/material
- Install JSON-server to create a mock backend for our application:
npm install -g json-server
Step 2: Create JSON-server mock data
- Create a new file named
db.json
in the root of your project. -
Add mock data to the
db.json
file to simulate a RESTful API. For example:{ "posts": [ { "id": 1, "title": "Post 1", "content": "Lorem ipsum dolor sit amet" }, { "id": 2, "title": "Post 2", "content": "Consectetur adipiscing elit" } ] }
- Start the JSON-server by running the following command:
json-server --watch db.json
Step 3: Create Angular components
-
Generate four new components for the CRUD operations:
ng generate component post-list ng generate component post-add ng generate component post-edit ng generate component post-detail
- Create a service to interact with the JSON-server:
ng generate service post
Step 4: Implement CRUD operations
-
Update the
post
service to make HTTP requests to the JSON-server. Use the Angular HttpClient module to send GET, POST, PUT, and DELETE requests. -
Implement the CRUD operations in the
post-list
,post-add
,post-edit
, andpost-detail
components. -
Display the posts in the
post-list
component using Material UI components like tables or cards. -
Create forms in the
post-add
andpost-edit
components to add new posts and edit existing posts. - Implement navigation between components using Angular Router.
Step 5: Testing the application
-
Start the Angular development server by running the following command:
ng serve
-
Open your browser and navigate to
http://localhost:4200
to see the application running. - Test the CRUD operations by adding, editing, and deleting posts.
Congratulations! You have successfully created a CRUD application using Angular 15, Material UI, and JSON-server. You can further customize the application by adding features like authentication, pagination, or search functionality. Thank you for following this tutorial, and happy coding!
i am not able to use color property in mat-toolbar can anyone suggest ? , i have to use class for this
what could be wrong in my code. the primary color is not changing?
i am facing cors error while fetching request from localhost json server, please help me to solve
Hi I am getting HttpResponse error kindly look into the error so that I can fix my error :- emp-add-edit.component.ts:48 HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: 'Unknown Error', url: 'http://localhost:3000/employees', ok: false, …}error: ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: 'error', …}headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, headers: Map(0)}message: "Http failure response for http://localhost:3000/employees: 0 Unknown Error"name: "HttpErrorResponse"ok: falsestatus: 0statusText: "Unknown Error"url: "http://localhost:3000/employees"%5B%5BPrototype%5D%5D: HttpResponseBase and fix it for me
Sir is it normal to increase in heart rate up to 115-120 after eating also why heart beat increases when going in sunlight,is this normal,Thanks in advance
Really helpful, and i got stuck my id is not in order like 1st id it's 4557 and 2nd is e616. can anyone share wat do to about this?
color:"primary" is not working in angular 18
very good explanation bro!…
Brat gap yo rahmat at dushi
Thank you very much for this awesome and easy-to-go tutorial.
Is it possible to getting it working github-pages or any other free hosting?
How the json server will run on any hosting?
great lesson, but not include validators in the field text. If the user wish include numbers in place, her can do. But it is not correct action.
nice work but after exporting source code save button is not working help me regarding this
Thank you very much Sir. This was the best tutorial I've ever seen on CRUD. I am a beginner so this was really helpful.
Really useful video❤, can you do that using backend api from using visual studio also
db.josn file is not showing in angular 16 how to fix this
i totally loved it,everything u taugh is working fine.the way u explain everything is very nice,thnaks you
35:33 Json Server Installation
43:33
incredible work , thank you
Great work!!