mirror of
https://github.com/Raghu-Ch/InventoryApp.git
synced 2026-02-10 04:43:02 -05:00
add product details & modify product service
This commit is contained in:
0
src/app/product/product-detail.component.css
Normal file
0
src/app/product/product-detail.component.css
Normal file
3
src/app/product/product-detail.component.html
Normal file
3
src/app/product/product-detail.component.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<p>
|
||||
product-detail works!
|
||||
</p>
|
||||
15
src/app/product/product-detail.component.ts
Normal file
15
src/app/product/product-detail.component.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-product-detail',
|
||||
templateUrl: './product-detail.component.html',
|
||||
styleUrls: ['./product-detail.component.css']
|
||||
})
|
||||
export class ProductDetailComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,3 +2,15 @@ table {
|
||||
width: 75%;
|
||||
margin: 20px auto 0 auto;
|
||||
}
|
||||
|
||||
section>mat-card {
|
||||
margin-top: 10px;
|
||||
width: 50%;
|
||||
margin: 10px auto;
|
||||
}
|
||||
|
||||
mat-card:hover {
|
||||
/* background: #02b3e4; */
|
||||
border: 2px solid #02b3e4;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<section fxFlex=50 class="aligner">
|
||||
<mat-card *ngFor="let product of products">{{product.productName}}</mat-card>
|
||||
<mat-card *ngFor="let product of products" (click)="getProductById(product._id)">
|
||||
{{product.productName}}</mat-card>
|
||||
</section>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { MatTableDataSource, MatSort } from '@angular/material';
|
||||
import { DataSource } from '@angular/cdk/table';
|
||||
import { RouterModule, Router } from '@angular/router';
|
||||
import { ProductService } from '../product/product.service';
|
||||
import { Product } from './product';
|
||||
|
||||
@Component({
|
||||
selector: 'app-product',
|
||||
@@ -9,20 +9,23 @@ import { ProductService } from '../product/product.service';
|
||||
styleUrls: ['./product.component.css']
|
||||
})
|
||||
export class ProductComponent implements OnInit {
|
||||
products: Product[];
|
||||
|
||||
products = [];
|
||||
displayedColumns = ['productName', 'brand', 'category', 'price'];
|
||||
|
||||
constructor(private productService: ProductService) { }
|
||||
constructor(private productService: ProductService, private router: Router) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.getAllProducts();
|
||||
}
|
||||
|
||||
getAllProducts(): void {
|
||||
this.productService.getProducts().subscribe((res: any[]) => {
|
||||
this.productService.getProducts().subscribe((res) => {
|
||||
this.products = res;
|
||||
console.log(this.products);
|
||||
});
|
||||
}
|
||||
|
||||
getProductById(id: string): void {
|
||||
this.productService.getProduct(id).subscribe(res => console.log(res));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,20 +4,22 @@ import { RouterModule } from '@angular/router';
|
||||
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
|
||||
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
|
||||
import {ProductComponent} from '../product/product.component';
|
||||
import { ProductDetailComponent } from './product-detail.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule,
|
||||
MatTableModule,
|
||||
MatCardModule
|
||||
MatCardModule,
|
||||
MatButtonModule
|
||||
],
|
||||
declarations: [
|
||||
ProductComponent
|
||||
ProductComponent,
|
||||
ProductDetailComponent
|
||||
]
|
||||
})
|
||||
export class ProductModule { }
|
||||
|
||||
@@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { Product } from './product';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -11,8 +13,14 @@ export class ProductService {
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getProducts(): Observable<any> {
|
||||
this.__url += '/products';
|
||||
return this.http.get(this.__url);
|
||||
getProducts(): Observable<Product[]> {
|
||||
const url = `${this.__url}/products`;
|
||||
return this.http.get<Product[]>(url);
|
||||
}
|
||||
|
||||
getProduct(id: string): Observable<Product> {
|
||||
const url = `${this.__url}/products/${id}`;
|
||||
console.log(url);
|
||||
return this.http.get<Product>(url);
|
||||
}
|
||||
}
|
||||
|
||||
16
src/app/product/product.ts
Normal file
16
src/app/product/product.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export class Product {
|
||||
id: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
category: string;
|
||||
brand: string;
|
||||
sku: string;
|
||||
resolution: string;
|
||||
type: string;
|
||||
technology: string;
|
||||
series: string;
|
||||
description: string;
|
||||
price: number;
|
||||
discount: string;
|
||||
imageUrl: string;
|
||||
}
|
||||
Reference in New Issue
Block a user