Crud Angular - Net Core - Angular-Material
Crud Angular - Net Core - Angular-Material
Add(“@nombre”,nombre );
sqlCommand.ExecuteNonQuery();
ANGULAR MATERIAL UI
ng add @angular/material
VISUALIZAR COMPONENTES
App.Module.ts
@NgModule ({
imports: [
MatSlideToggleModule,
})
class AppModule {}
<mat-slide-toggle>Toggle me!</mat-slide-toggle>
/**
* @title Basic use of `<table mat-table>`
*/
@Component({
selector: 'table-basic-example',
styleUrls: ['table-basic-example.css'],
templateUrl: 'table-basic-example.html',
})
export class TableBasicExample {
displayedColumns: string[] = ['position', 'name', 'weight',
'symbol'];
dataSource = ELEMENT_DATA;
}
table {
width: 100%;
}
Agregando Paginador
1. Agregar al app.module.ts
ngAfterViewInit: se ejecuta después del render. En este se manejan de forma programática los
hijos del componente.
@Component({
selector: 'app-tipos',
templateUrl: './tipos.component.html',
styleUrls: ['./tipos.component.css']
})
export class TiposComponent {
displayedColumns: string[] = ['id',
'nombre','responsable','acciones'];
dataSource = new MatTableDataSource<Tipos>(tipos);
@ViewChild(MatPaginator) paginator!: MatPaginator;
ngOnInit(){
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
}
}
<ng-container matColumnDef="acciones">
<th mat-header-cell *matHeaderCellDef> Acciones </th>
<td mat-cell *matCellDef="let element">
<mat-icon class="search" matTooltip="Ver"
fontIcon="search" routerLink="/getInspection/{{element.id}}"></mat-
icon>
<mat-icon class="edit" matTooltip="Editar"
fontIcon="edit"></mat-icon>
<mat-icon class="delete"
matTooltip="Borrar"fontIcon="delete"
(onclick)=”eliminarMascota(element.id)”></mat-icon>
</td>
Agregar al app.moudule.ts
Ng g c Components/detalle
@Component({
selector: 'app-detalle',
templateUrl: './detalle.component.html',
styleUrls: ['./detalle.component.css']
})
export class DetalleComponent {
id!:number;
inspeccion!: Tipos;
inspeccion$! :Observable<Tipos>;
constructor(private inspectiontypeservice: InspectionTypeService,
private activatedRoute: ActivatedRoute){
this.id = +this.activatedRoute.snapshot.paramMap.get('id')!;
}
ngOnInit(){
//this.getInspectionById();
this.inspeccion$ =
this.inspectiontypeservice.getInspectionTypebyId(this.id);
}
getInspectionById(){
/* return
this.inspectiontypeservice.getInspectionTypebyId(this.id).subscribe(d
ata=>{
this.inspeccion = data;
})*/
}
Detalle.html
<mat-card>
<div *ngIf="inspeccion$ | async as inspeccion" class="container
text-center">
<!-- <div *ngIf="inspeccion != null" class="container text-
center">
-->
<mat-card-title>Id: {{inspeccion.id}}</mat-card-title>
<mat-card-content>
<h3>Nombre: {{inspeccion.nombre}}</h3>
<h3>Responsable: {{inspeccion.responsable}}</h3>
</mat-card-content>
</div>
</mat-card>
ELIMINAR
ngOnInit(){
getTipos();
}
getTipos(){
this.inspectiontypeservice.getInspectionType().subscribe(res =>{
console.log(res);
this.dataSource.data = res;
});
eliminarMascota(id:number){
return
this.inspectiontypeservice.deleteinspectionType(id).subscribe(data=>{
/*this.toast.success('Registro eliminado satisfactoriamente!');*/
alert('Delete')
this.getTipos();
})
}
AGREGAR
Ng g c Components/add-tipos
App.module.ts
import {MatGridListModule} from '@angular/material/grid-list';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';
Html
.ts
.appmodule.ts