mirror of
https://github.com/Raghu-Ch/InventoryApp.git
synced 2026-02-10 12:53:03 -05:00
initial commit
This commit is contained in:
4
src/app/product/product.component.css
Normal file
4
src/app/product/product.component.css
Normal file
@@ -0,0 +1,4 @@
|
||||
table {
|
||||
width: 75%;
|
||||
margin: 20px auto 0 auto;
|
||||
}
|
||||
3
src/app/product/product.component.html
Normal file
3
src/app/product/product.component.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<section fxFlex=50 class="aligner">
|
||||
<mat-card *ngFor="let product of products">{{product.productName}}</mat-card>
|
||||
</section>
|
||||
30
src/app/product/product.component.ts
Normal file
30
src/app/product/product.component.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { MatTableDataSource, MatSort } from '@angular/material';
|
||||
import { DataSource } from '@angular/cdk/table';
|
||||
import { ProductService } from '../product/product.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-product',
|
||||
templateUrl: './product.component.html',
|
||||
styleUrls: ['./product.component.css']
|
||||
})
|
||||
export class ProductComponent implements OnInit {
|
||||
|
||||
products = [];
|
||||
displayedColumns = ['productName', 'brand', 'category', 'price'];
|
||||
// dataSource = new MatTableDataSource(this.productService);
|
||||
// dataSource = this.products;
|
||||
|
||||
constructor(private productService: ProductService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.getAllProducts();
|
||||
}
|
||||
|
||||
getAllProducts(): void {
|
||||
this.productService.getProducts().subscribe((res: any[]) => {
|
||||
this.products = res;
|
||||
console.log(this.products);
|
||||
});
|
||||
}
|
||||
}
|
||||
13
src/app/product/product.module.spec.ts
Normal file
13
src/app/product/product.module.spec.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { ProductModule } from './product.module';
|
||||
|
||||
describe('ProductModule', () => {
|
||||
let productModule: ProductModule;
|
||||
|
||||
beforeEach(() => {
|
||||
productModule = new ProductModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(productModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
23
src/app/product/product.module.ts
Normal file
23
src/app/product/product.module.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterModule } from '@angular/router';
|
||||
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
|
||||
|
||||
|
||||
import {ProductComponent} from '../product/product.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule,
|
||||
MatTableModule,
|
||||
MatCardModule
|
||||
],
|
||||
declarations: [
|
||||
ProductComponent
|
||||
]
|
||||
})
|
||||
export class ProductModule { }
|
||||
15
src/app/product/product.service.spec.ts
Normal file
15
src/app/product/product.service.spec.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { ProductService } from './product.service';
|
||||
|
||||
describe('ProductService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProductService], (service: ProductService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
17
src/app/product/product.service.ts
Normal file
17
src/app/product/product.service.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProductService {
|
||||
|
||||
url = 'https://fast-ravine-56232.herokuapp.com/api/products';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getProducts(): Observable<any> {
|
||||
return this.http.get(this.url);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user