mirror of
https://github.com/Raghu-Ch/InventoryApp.git
synced 2026-02-10 12:53:03 -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%;
|
width: 75%;
|
||||||
margin: 20px auto 0 auto;
|
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">
|
<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>
|
</section>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { MatTableDataSource, MatSort } from '@angular/material';
|
import { RouterModule, Router } from '@angular/router';
|
||||||
import { DataSource } from '@angular/cdk/table';
|
|
||||||
import { ProductService } from '../product/product.service';
|
import { ProductService } from '../product/product.service';
|
||||||
|
import { Product } from './product';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-product',
|
selector: 'app-product',
|
||||||
@@ -9,20 +9,23 @@ import { ProductService } from '../product/product.service';
|
|||||||
styleUrls: ['./product.component.css']
|
styleUrls: ['./product.component.css']
|
||||||
})
|
})
|
||||||
export class ProductComponent implements OnInit {
|
export class ProductComponent implements OnInit {
|
||||||
|
products: Product[];
|
||||||
|
|
||||||
products = [];
|
constructor(private productService: ProductService, private router: Router) { }
|
||||||
displayedColumns = ['productName', 'brand', 'category', 'price'];
|
|
||||||
|
|
||||||
constructor(private productService: ProductService) { }
|
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.getAllProducts();
|
this.getAllProducts();
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllProducts(): void {
|
getAllProducts(): void {
|
||||||
this.productService.getProducts().subscribe((res: any[]) => {
|
this.productService.getProducts().subscribe((res) => {
|
||||||
this.products = res;
|
this.products = res;
|
||||||
console.log(this.products);
|
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 { MatTableModule } from '@angular/material/table';
|
||||||
import { MatCardModule } from '@angular/material/card';
|
import { MatCardModule } from '@angular/material/card';
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
|
||||||
|
|
||||||
import {ProductComponent} from '../product/product.component';
|
import {ProductComponent} from '../product/product.component';
|
||||||
|
import { ProductDetailComponent } from './product-detail.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
RouterModule,
|
RouterModule,
|
||||||
MatTableModule,
|
MatTableModule,
|
||||||
MatCardModule
|
MatCardModule,
|
||||||
|
MatButtonModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
ProductComponent
|
ProductComponent,
|
||||||
|
ProductDetailComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class ProductModule { }
|
export class ProductModule { }
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
import { Product } from './product';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
@@ -11,8 +13,14 @@ export class ProductService {
|
|||||||
|
|
||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
getProducts(): Observable<any> {
|
getProducts(): Observable<Product[]> {
|
||||||
this.__url += '/products';
|
const url = `${this.__url}/products`;
|
||||||
return this.http.get(this.__url);
|
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