Refractoring
This commit is contained in:
		
							parent
							
								
									9e53885330
								
							
						
					
					
						commit
						fff4157bca
					
				| @ -1,9 +1,5 @@ | |||||||
| <app-nav-bar></app-nav-bar> | <app-nav-bar></app-nav-bar> | ||||||
| <div class="container" style="margin-top: 140px;"> | <div class="container" style="margin-top: 140px;"> | ||||||
|     <h1>Welcome to {{title}}</h1> |     <h1>Welcome to {{title}}</h1> | ||||||
|     <ul> |     <app-shop></app-shop> | ||||||
|         <li class="list-unstyled" *ngFor="let product of products"> |  | ||||||
|             {{product.name}} |  | ||||||
|         </li> |  | ||||||
|     </ul> |  | ||||||
| </div> | </div> | ||||||
| @ -1,7 +1,4 @@ | |||||||
| import { HttpClient } from '@angular/common/http'; |  | ||||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||||
| import { IPagination } from './models/pagination'; |  | ||||||
| import { IProduct } from './models/product'; |  | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: 'app-root', |   selector: 'app-root', | ||||||
| @ -10,17 +7,8 @@ import { IProduct } from './models/product'; | |||||||
| }) | }) | ||||||
| export class AppComponent implements OnInit { | export class AppComponent implements OnInit { | ||||||
|   title = 'E-Commerce'; |   title = 'E-Commerce'; | ||||||
|   products: IProduct[]; |  | ||||||
| 
 | 
 | ||||||
|   constructor(private http: HttpClient) {} |   constructor() {} | ||||||
| 
 | 
 | ||||||
|   ngOnInit(): void { |   ngOnInit(): void {} | ||||||
|     this.http.get('https://localhost:5001/api/products?pageSize=50').subscribe( |  | ||||||
|       { |  | ||||||
|         next: (response: IPagination) => { this.products = response.data; }, |  | ||||||
|         error: (e: any) => { console.log(e); }, |  | ||||||
|         complete: () => { console.log('complete'); } |  | ||||||
|       } |  | ||||||
|     ); |  | ||||||
|   } |  | ||||||
| } | } | ||||||
| @ -5,18 +5,20 @@ import { HttpClientModule } from '@angular/common/http'; | |||||||
| import { AppRoutingModule } from './app-routing.module'; | import { AppRoutingModule } from './app-routing.module'; | ||||||
| import { AppComponent } from './app.component'; | import { AppComponent } from './app.component'; | ||||||
| import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||||||
| import { NavBarComponent } from './nav-bar/nav-bar.component'; | import { CoreModule } from './core/core.module'; | ||||||
|  | import { ShopModule } from './shop/shop.module'; | ||||||
| 
 | 
 | ||||||
| @NgModule({ | @NgModule({ | ||||||
|   declarations: [ |   declarations: [ | ||||||
|     AppComponent, |     AppComponent | ||||||
|     NavBarComponent |  | ||||||
|   ], |   ], | ||||||
|   imports: [ |   imports: [ | ||||||
|     BrowserModule, |     BrowserModule, | ||||||
|     AppRoutingModule, |     AppRoutingModule, | ||||||
|     BrowserAnimationsModule, |     BrowserAnimationsModule, | ||||||
|     HttpClientModule |     HttpClientModule, | ||||||
|  |     CoreModule, | ||||||
|  |     ShopModule | ||||||
|   ], |   ], | ||||||
|   providers: [], |   providers: [], | ||||||
|   bootstrap: [AppComponent] |   bootstrap: [AppComponent] | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								client/src/app/core/core.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								client/src/app/core/core.module.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | import { NgModule } from '@angular/core'; | ||||||
|  | import { CommonModule } from '@angular/common'; | ||||||
|  | import { NavBarComponent } from './nav-bar/nav-bar.component'; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @NgModule({ | ||||||
|  |   declarations: [NavBarComponent], | ||||||
|  |   imports: [ | ||||||
|  |     CommonModule | ||||||
|  |   ], | ||||||
|  |   exports: [NavBarComponent] | ||||||
|  | }) | ||||||
|  | export class CoreModule { } | ||||||
							
								
								
									
										12
									
								
								client/src/app/shared/shared.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								client/src/app/shared/shared.module.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | import { NgModule } from '@angular/core'; | ||||||
|  | import { CommonModule } from '@angular/common'; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @NgModule({ | ||||||
|  |   declarations: [], | ||||||
|  |   imports: [ | ||||||
|  |     CommonModule | ||||||
|  |   ] | ||||||
|  | }) | ||||||
|  | export class SharedModule { } | ||||||
							
								
								
									
										12
									
								
								client/src/app/shop/shop-routing.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								client/src/app/shop/shop-routing.module.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | import { NgModule } from '@angular/core'; | ||||||
|  | import { CommonModule } from '@angular/common'; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @NgModule({ | ||||||
|  |   declarations: [], | ||||||
|  |   imports: [ | ||||||
|  |     CommonModule | ||||||
|  |   ] | ||||||
|  | }) | ||||||
|  | export class ShopRoutingModule { } | ||||||
							
								
								
									
										5
									
								
								client/src/app/shop/shop.component.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								client/src/app/shop/shop.component.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | <ul> | ||||||
|  |   <li class="list-unstyled" *ngFor="let product of products"> | ||||||
|  |     {{product.name}} | ||||||
|  |   </li> | ||||||
|  | </ul> | ||||||
							
								
								
									
										0
									
								
								client/src/app/shop/shop.component.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								client/src/app/shop/shop.component.scss
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										26
									
								
								client/src/app/shop/shop.component.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								client/src/app/shop/shop.component.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | |||||||
|  | import { Component, OnInit } from '@angular/core'; | ||||||
|  | import { IProduct } from '../shared/models/product'; | ||||||
|  | import { ShopService } from './shop.service'; | ||||||
|  | 
 | ||||||
|  | @Component({ | ||||||
|  |   selector: 'app-shop', | ||||||
|  |   templateUrl: './shop.component.html', | ||||||
|  |   styleUrls: ['./shop.component.scss'] | ||||||
|  | }) | ||||||
|  | export class ShopComponent implements OnInit { | ||||||
|  | 
 | ||||||
|  |   products: IProduct[]; | ||||||
|  | 
 | ||||||
|  |   constructor(private shopService: ShopService) { } | ||||||
|  | 
 | ||||||
|  |   ngOnInit(): void { | ||||||
|  |     this.shopService.getProducts().subscribe( | ||||||
|  |       { | ||||||
|  |         next: (response) => { this.products = response.data; }, | ||||||
|  |         error: (e: any) => { console.log(e); }, | ||||||
|  |         complete: () => { console.log('complete'); } | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										16
									
								
								client/src/app/shop/shop.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								client/src/app/shop/shop.module.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | |||||||
|  | import { NgModule } from '@angular/core'; | ||||||
|  | import { CommonModule } from '@angular/common'; | ||||||
|  | import { ShopComponent } from './shop.component'; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @NgModule({ | ||||||
|  |   declarations: [ | ||||||
|  |     ShopComponent | ||||||
|  |   ], | ||||||
|  |   imports: [ | ||||||
|  |     CommonModule | ||||||
|  |   ], | ||||||
|  |   exports: [ShopComponent] | ||||||
|  | }) | ||||||
|  | export class ShopModule { } | ||||||
							
								
								
									
										16
									
								
								client/src/app/shop/shop.service.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								client/src/app/shop/shop.service.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | |||||||
|  | import { HttpClient } from '@angular/common/http'; | ||||||
|  | import { Injectable } from '@angular/core'; | ||||||
|  | import { IPagination } from '../shared/models/pagination'; | ||||||
|  | 
 | ||||||
|  | @Injectable({ | ||||||
|  |   providedIn: 'root' | ||||||
|  | }) | ||||||
|  | export class ShopService { | ||||||
|  |   baseURL = 'https://localhost:5001/api/' | ||||||
|  | 
 | ||||||
|  |   constructor(private http: HttpClient) { } | ||||||
|  | 
 | ||||||
|  |   getProducts(){ | ||||||
|  |     return this.http.get<IPagination>(this.baseURL + 'products'); | ||||||
|  |   } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user