AllAngularProjects

Angular : Create Product List And API Call | Create ECommerce Angular Project With API Call

Angular : Create Product List And API Call | Create ECommerce Angular Project With API Call

First Install Bootstrap For CSS

ng i bootstrap

Create Model For This Project

models/product.model.ts

export interface ProductModel{
        id?:number,
        title :string,
        description: string,
        image_url:string,
        price:string,
        review:string,
        rating:string,
        link?:string,
        category:string,
}

services/product.service.ts

import { HttpClient,HttpHeaders } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { ProductModel } from "../models/product.model";

@Injectable()
export class ProductService{

base_url="http://localhost:5000/";
http_service:HttpClient;
constructor(private http_client:HttpClient){
this.http_service=http_client;
}

getProductlist(){
    let httpOptions = {
        headers: new HttpHeaders({
            'Content-Type': 'application/json',
        }),
    }
    return this.http_service.get(this.base_url+"product",httpOptions)
}
getlimitProductlist(limit:number){

    let httpOptions = {
        headers: new HttpHeaders({
            'Content-Type': 'application/json',
        }),
    }
    return this.http_service.get(this.base_url+"product?limit="+limit,httpOptions)
}
getSingleProduct(id:number)
{
    let httpOptions = {
        headers: new HttpHeaders({
            'Content-Type': 'application/json',
        }),
    }
    return this.http_service.get(this.base_url+"product/"+id,httpOptions)
}
addProductService(product:ProductModel){
    let httpOptions={
        data:product,
        headers:new HttpHeaders({
            'Content-Type':"application/json"
        })
    }
    return this.http_service.post(this.base_url+'product',httpOptions).subscribe();
}

}

2 thoughts on “Angular : Create Product List And API Call | Create ECommerce Angular Project With API Call

Leave a Reply

10 Best Artificial Intelligence Software|artificial intelligence tools 5 nft games to earn money | Best NFT games for earn crypto Earn Money From Minting NFTs| How to mint NFT for free Top 10 Things You Need To Know About Python List | python lists functions 10 Popular PHP frameworks for web developers| best php frameworks 12 Tips On How To Become a Python Developer | python For beginner 12 Best Nodejs Frameworks for App Development in 2022 how to create google web stories, Steps to create web stories Top 10 Features in Angular 13 Every Developer Should Know | Angular 13 Features 10 Best Angular UI Libraries | angular ui components | angular Project 10 Best Web Development Frameworks in 2022 Frontend & Backend 18 Best Open-Source and Free Database Software | best database software for beginners Top 10+ Best Java IDEs & Online Java Compilers | best java ide for beginners top 10 besic to andvance java books |java books for beginer Top 5 Themes For Blogger, professional blogger theme download BEST Python Courses Online,Top 10 Courses to Learn Python in 2022 Top 13 python libraries for data science