This repository was archived by the owner on Nov 9, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +65
-1
lines changed
components/product/product-remove Expand file tree Collapse file tree 4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import { MatSortModule } from '@angular/material/sort';
3030import localePt from '@angular/common/locales/pt' ;
3131import { registerLocaleData } from '@angular/common' ;
3232import { ProductUpdateComponent } from './components/product/product-update/product-update.component' ;
33+ import { ProductRemoveComponent } from './components/product/product-remove/product-remove.component' ;
3334
3435registerLocaleData ( localePt ) ;
3536
@@ -45,7 +46,8 @@ registerLocaleData(localePt);
4546 ProductCreateComponent ,
4647 ProductReadComponent ,
4748 MatTemplateTableComponent ,
48- ProductUpdateComponent
49+ ProductUpdateComponent ,
50+ ProductRemoveComponent
4951 ] ,
5052 imports : [
5153 BrowserModule ,
Original file line number Diff line number Diff line change 1+ @import "../product-create/product-create.component.css" ;
Original file line number Diff line number Diff line change 1+ < mat-card >
2+ < mat-card-title > Remove '{{ product.nome }}'?</ mat-card-title >
3+ < form >
4+ < mat-form-field >
5+ < input matInput placeholder ="Name " name ="name " [(ngModel)] ="product.nome ">
6+ </ mat-form-field >
7+ < mat-form-field >
8+ < input matInput placeholder ="Description " name ="description " [(ngModel)] ="product.descricao ">
9+ </ mat-form-field >
10+ < mat-form-field >
11+ < input matInput placeholder ="Price (R$) " name ="price " [(ngModel)] ="product.precoUnitario ">
12+ </ mat-form-field >
13+ </ form >
14+
15+ < button (click) ="delete() " mat-raised-button color ="warn ">
16+ Remove
17+ </ button >
18+ < button (click) ="navigateToProducts() " mat-raised-button >
19+ Cancel
20+ </ button >
21+ </ mat-card >
Original file line number Diff line number Diff line change 1+ import { Component , OnInit } from '@angular/core' ;
2+ import { ActivatedRoute , Router } from '@angular/router' ;
3+ import { Product } from '../product.model' ;
4+ import { ProductService } from '../product.service' ;
5+
6+ @Component ( {
7+ selector : "app-product-remove" ,
8+ templateUrl : "./product-remove.component.html" ,
9+ styleUrls : [ "./product-remove.component.css" ] ,
10+ } )
11+ export class ProductRemoveComponent implements OnInit {
12+ product : Product ;
13+
14+ constructor (
15+ private service : ProductService ,
16+ private router : Router ,
17+ private route : ActivatedRoute
18+ ) { }
19+
20+ ngOnInit ( ) : void {
21+ const id = this . route . snapshot . paramMap . get ( "id" ) ;
22+ this . service . getById ( id ) . subscribe ( ( found ) => {
23+ this . product = found ;
24+ } )
25+ }
26+
27+ delete ( ) : void {
28+ const idToDelete = this . product . id . toString ( ) ;
29+ this . service . delete ( idToDelete ) . subscribe ( ( ) => {
30+ this . service . showMessage (
31+ `The item id. ${ idToDelete } was removed from database.`
32+ ) ;
33+ } ) ;
34+ this . navigateToProducts ( ) ;
35+ }
36+
37+ navigateToProducts ( ) : void {
38+ this . router . navigate ( [ "/products" ] ) ;
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments