├── src
├── assets
│ └── .gitkeep
├── app
│ ├── acerca-de
│ │ ├── acerca-de.component.css
│ │ ├── acerca-de.component.html
│ │ ├── acerca-de.component.ts
│ │ └── acerca-de.component.spec.ts
│ ├── agregar-mascota
│ │ ├── agregar-mascota.component.css
│ │ ├── agregar-mascota.component.html
│ │ ├── agregar-mascota.component.spec.ts
│ │ └── agregar-mascota.component.ts
│ ├── editar-mascota
│ │ ├── editar-mascota.component.css
│ │ ├── editar-mascota.component.html
│ │ ├── editar-mascota.component.spec.ts
│ │ └── editar-mascota.component.ts
│ ├── listar-mascotas
│ │ ├── listar-mascotas.component.css
│ │ ├── listar-mascotas.component.spec.ts
│ │ ├── listar-mascotas.component.html
│ │ └── listar-mascotas.component.ts
│ ├── dialogo-confirmacion
│ │ ├── dialogo-confirmacion.component.css
│ │ ├── dialogo-confirmacion.component.html
│ │ ├── dialogo-confirmacion.component.ts
│ │ └── dialogo-confirmacion.component.spec.ts
│ ├── app.component.css
│ ├── mascota.spec.ts
│ ├── mascota.ts
│ ├── app.component.ts
│ ├── mascotas.service.spec.ts
│ ├── mascotas.service.ts
│ ├── app.component.html
│ ├── app-routing.module.ts
│ ├── app.component.spec.ts
│ └── app.module.ts
├── favicon.ico
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── styles.css
├── main.ts
├── test.ts
├── index.html
└── polyfills.ts
├── server
├── esquema.sql
├── getAll.php
├── bd.php
├── get.php
├── post.php
├── delete.php
└── update.php
├── e2e
├── tsconfig.json
├── src
│ ├── app.po.ts
│ └── app.e2e-spec.ts
└── protractor.conf.js
├── .editorconfig
├── tsconfig.app.json
├── tsconfig.spec.json
├── browserslist
├── tsconfig.json
├── .gitignore
├── karma.conf.js
├── README.md
├── package.json
├── tslint.json
└── angular.json
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/acerca-de/acerca-de.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/agregar-mascota/agregar-mascota.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/editar-mascota/editar-mascota.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/listar-mascotas/listar-mascotas.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/dialogo-confirmacion/dialogo-confirmacion.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parzibyte/crud-angular-php-mysql/HEAD/src/favicon.ico
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true,
3 | baseUrl: ".",
4 | };
5 |
--------------------------------------------------------------------------------
/src/app/acerca-de/acerca-de.component.html:
--------------------------------------------------------------------------------
1 |
Acerca de
2 |
3 | Creado y mantenido por Parzibyte
4 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 | html, body { height: 100%; }
3 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
4 |
--------------------------------------------------------------------------------
/server/esquema.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE `mascotas` (
2 | `id` bigint(20) UNSIGNED NOT NULL primary key AUTO_INCREMENT,
3 | `nombre` varchar(255) NOT NULL,
4 | `raza` varchar(255) NOT NULL,
5 | `edad` tinyint(4) DEFAULT NULL
6 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--------------------------------------------------------------------------------
/src/app/app.component.css:
--------------------------------------------------------------------------------
1 | .contenedor-padre {
2 | display: flex;
3 | flex-flow: column;
4 | height: 100%;
5 | }
6 |
7 | .barra {
8 | flex: 0 1 auto;
9 | }
10 |
11 | .contenido {
12 | flex: 1 1 auto;
13 | }
14 |
15 | .padding-10 {
16 | padding: 10px;
17 | }
--------------------------------------------------------------------------------
/e2e/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/e2e",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get(browser.baseUrl) as Promise;
6 | }
7 |
8 | getTitleText() {
9 | return element(by.css('app-root .content span')).getText() as Promise;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/dialogo-confirmacion/dialogo-confirmacion.component.html:
--------------------------------------------------------------------------------
1 | Confirmación
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/app",
5 | "types": []
6 | },
7 | "files": [
8 | "src/main.ts",
9 | "src/polyfills.ts"
10 | ],
11 | "include": [
12 | "src/**/*.ts"
13 | ],
14 | "exclude": [
15 | "src/test.ts",
16 | "src/**/*.spec.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "src/test.ts",
12 | "src/polyfills.ts"
13 | ],
14 | "include": [
15 | "src/**/*.spec.ts",
16 | "src/**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
--------------------------------------------------------------------------------
/browserslist:
--------------------------------------------------------------------------------
1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 |
5 | # You can see what browsers were selected by your queries by running:
6 | # npx browserslist
7 |
8 | > 0.5%
9 | last 2 versions
10 | Firefox ESR
11 | not dead
12 | not IE 9-11 # For IE 9-11 support, remove 'not'.
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "outDir": "./dist/out-tsc",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "downlevelIteration": true,
9 | "experimentalDecorators": true,
10 | "module": "esnext",
11 | "moduleResolution": "node",
12 | "importHelpers": true,
13 | "target": "es2015",
14 | "typeRoots": [
15 | "node_modules/@types"
16 | ],
17 | "lib": [
18 | "es2018",
19 | "dom"
20 | ]
21 | },
22 | "angularCompilerOptions": {
23 | "fullTemplateTypeCheck": true,
24 | "strictInjectionParameters": true
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: any;
11 |
12 | // First, initialize the Angular testing environment.
13 | getTestBed().initTestEnvironment(
14 | BrowserDynamicTestingModule,
15 | platformBrowserDynamicTesting()
16 | );
17 | // Then we find all the tests.
18 | const context = require.context('./', true, /\.spec\.ts$/);
19 | // And load the modules.
20 | context.keys().map(context);
21 |
--------------------------------------------------------------------------------
/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 | import { browser, logging } from 'protractor';
3 |
4 | describe('workspace-project App', () => {
5 | let page: AppPage;
6 |
7 | beforeEach(() => {
8 | page = new AppPage();
9 | });
10 |
11 | it('should display welcome message', () => {
12 | page.navigateTo();
13 | expect(page.getTitleText()).toEqual('crud-angular-php-mysql app is running!');
14 | });
15 |
16 | afterEach(async () => {
17 | // Assert that there are no errors emitted from the browser
18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19 | expect(logs).not.toContain(jasmine.objectContaining({
20 | level: logging.Level.SEVERE,
21 | } as logging.Entry));
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false,
7 | baseUrl: "http://localhost/mascotas_angular",
8 | };
9 |
10 | /*
11 | * For easier debugging in development mode, you can import the following file
12 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
13 | *
14 | * This import should be commented out in production mode because it will have a negative impact
15 | * on performance if an error is thrown.
16 | */
17 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | # Only exists if Bazel was run
8 | /bazel-out
9 |
10 | # dependencies
11 | /node_modules
12 |
13 | # profiling files
14 | chrome-profiler-events*.json
15 | speed-measure-plugin*.json
16 |
17 | # IDEs and editors
18 | /.idea
19 | .project
20 | .classpath
21 | .c9/
22 | *.launch
23 | .settings/
24 | *.sublime-workspace
25 |
26 | # IDE - VSCode
27 | .vscode/*
28 | !.vscode/settings.json
29 | !.vscode/tasks.json
30 | !.vscode/launch.json
31 | !.vscode/extensions.json
32 | .history/*
33 |
34 | # misc
35 | /.sass-cache
36 | /connect.lock
37 | /coverage
38 | /libpeerconnection.log
39 | npm-debug.log
40 | yarn-error.log
41 | testem.log
42 | /typings
43 |
44 | # System Files
45 | .DS_Store
46 | Thumbs.db
47 |
--------------------------------------------------------------------------------
/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 | // Protractor configuration file, see link for more information
3 | // https://github.com/angular/protractor/blob/master/lib/config.ts
4 |
5 | const { SpecReporter } = require('jasmine-spec-reporter');
6 |
7 | /**
8 | * @type { import("protractor").Config }
9 | */
10 | exports.config = {
11 | allScriptsTimeout: 11000,
12 | specs: [
13 | './src/**/*.e2e-spec.ts'
14 | ],
15 | capabilities: {
16 | browserName: 'chrome'
17 | },
18 | directConnect: true,
19 | baseUrl: 'http://localhost:4200/',
20 | framework: 'jasmine',
21 | jasmineNodeOpts: {
22 | showColors: true,
23 | defaultTimeoutInterval: 30000,
24 | print: function() {}
25 | },
26 | onPrepare() {
27 | require('ts-node').register({
28 | project: require('path').join(__dirname, './tsconfig.json')
29 | });
30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
31 | }
32 | };
--------------------------------------------------------------------------------
/src/app/mascota.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { Mascota } from './mascota';
19 |
20 | describe('Mascota', () => {
21 | it('should create an instance', () => {
22 | expect(new Mascota()).toBeTruthy();
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/src/app/mascota.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | export class Mascota {
19 | constructor(
20 | public nombre: string,
21 | public raza: string,
22 | public edad: number,
23 | public id?: number,
24 | ) { }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/app/agregar-mascota/agregar-mascota.component.html:
--------------------------------------------------------------------------------
1 | Agregar mascota pets
2 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { Component } from '@angular/core';
19 |
20 | @Component({
21 | selector: 'app-root',
22 | templateUrl: './app.component.html',
23 | styleUrls: ['./app.component.css']
24 | })
25 | export class AppComponent {
26 | title = 'crud-angular-php-mysql';
27 | }
28 |
--------------------------------------------------------------------------------
/server/getAll.php:
--------------------------------------------------------------------------------
1 |
19 | query("select id, nombre, raza, edad from mascotas");
23 | $mascotas = $sentencia->fetchAll(PDO::FETCH_OBJ);
24 | echo json_encode($mascotas);
25 |
--------------------------------------------------------------------------------
/src/app/editar-mascota/editar-mascota.component.html:
--------------------------------------------------------------------------------
1 | Editar mascota pets
2 |
--------------------------------------------------------------------------------
/server/bd.php:
--------------------------------------------------------------------------------
1 |
19 | getMessage();
27 | }
28 |
--------------------------------------------------------------------------------
/src/app/acerca-de/acerca-de.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { Component, OnInit } from '@angular/core';
19 |
20 | @Component({
21 | selector: 'app-acerca-de',
22 | templateUrl: './acerca-de.component.html',
23 | styleUrls: ['./acerca-de.component.css']
24 | })
25 | export class AcercaDeComponent implements OnInit {
26 |
27 | constructor() { }
28 |
29 | ngOnInit() {
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, './coverage/crud-angular-php-mysql'),
20 | reports: ['html', 'lcovonly', 'text-summary'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false,
30 | restartOnFileChange: true
31 | });
32 | };
33 |
--------------------------------------------------------------------------------
/src/app/mascotas.service.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { TestBed } from '@angular/core/testing';
19 |
20 | import { MascotasService } from './mascotas.service';
21 |
22 | describe('MascotasService', () => {
23 | beforeEach(() => TestBed.configureTestingModule({}));
24 |
25 | it('should be created', () => {
26 | const service: MascotasService = TestBed.get(MascotasService);
27 | expect(service).toBeTruthy();
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/server/get.php:
--------------------------------------------------------------------------------
1 |
19 | prepare("select id, nombre, raza, edad from mascotas where id = ?");
27 | $sentencia->execute([$idMascota]);
28 | $mascota = $sentencia->fetchObject();
29 | echo json_encode($mascota);
30 |
--------------------------------------------------------------------------------
/server/post.php:
--------------------------------------------------------------------------------
1 |
19 | prepare("insert into mascotas(nombre, raza, edad) values (?,?,?)");
28 | $resultado = $sentencia->execute([$jsonMascota->nombre, $jsonMascota->raza, $jsonMascota->edad]);
29 | echo json_encode([
30 | "resultado" => $resultado,
31 | ]);
32 |
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 | CRUD Angular con PHP y MySQL
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/server/delete.php:
--------------------------------------------------------------------------------
1 |
19 | prepare("DELETE FROM mascotas WHERE id = ?");
33 | $resultado = $sentencia->execute([$idMascota]);
34 | echo json_encode($resultado);
35 |
--------------------------------------------------------------------------------
/server/update.php:
--------------------------------------------------------------------------------
1 |
19 | prepare("UPDATE mascotas SET nombre = ?, raza = ?, edad = ? WHERE id = ?");
32 | $resultado = $sentencia->execute([$jsonMascota->nombre, $jsonMascota->raza, $jsonMascota->edad, $jsonMascota->id]);
33 | echo json_encode($resultado);
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Conexión Angular, PHP y MySQL
3 | 
4 | ## Descripción
5 |
6 | Vamos a usar PHP así que es necesario configurar [CORS](https://parzibyte.me/blog/2019/11/10/configurar-cors-php/). Para la base de datos vamos a usar MySQL, si quieres puedes comenzar aprendiendo [PHP y MySQL](https://parzibyte.me/blog/2018/02/12/mysql-php-pdo-crud/).
7 |
8 | Después vamos a crear la app de Angular, todos los componentes son generados con la [CLI](https://parzibyte.me/blog/2019/11/03/instalar-cli-angular-windows/). Más tarde se agrega [Angular Material](https://parzibyte.me/blog/2019/11/03/agregar-angular-material-app-angular/), se crea un [servicio](https://parzibyte.me/blog/2019/11/08/servicios-angular-ejemplo/) que usa el módulo [HttpClient](https://parzibyte.me/blog/2019/11/10/angular-peticiones-http-httpclient/), un momento más tarde se configura el [router](https://parzibyte.me/blog/2019/11/04/angular-router-tutorial-ejemplo/) y en algunos componentes utilizamos [formularios](https://parzibyte.me/blog/2019/11/25/ejemplo-formulario-angular/).
9 | ## Tutorial y demostración
10 | Tutorial: https://parzibyte.me/blog/2019/11/25/angular-php-mysql-crud/
11 |
12 | Demo: https://parzibyte.me/ejemplos/mascotas_angular/
13 |
14 | Descargar versión compilada: https://github.com/parzibyte/crud-angular-php-mysql/releases/download/v1.0/mascotas_angular.zip
--------------------------------------------------------------------------------
/src/app/acerca-de/acerca-de.component.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
19 |
20 | import { AcercaDeComponent } from './acerca-de.component';
21 |
22 | describe('AcercaDeComponent', () => {
23 | let component: AcercaDeComponent;
24 | let fixture: ComponentFixture;
25 |
26 | beforeEach(async(() => {
27 | TestBed.configureTestingModule({
28 | declarations: [ AcercaDeComponent ]
29 | })
30 | .compileComponents();
31 | }));
32 |
33 | beforeEach(() => {
34 | fixture = TestBed.createComponent(AcercaDeComponent);
35 | component = fixture.componentInstance;
36 | fixture.detectChanges();
37 | });
38 |
39 | it('should create', () => {
40 | expect(component).toBeTruthy();
41 | });
42 | });
43 |
--------------------------------------------------------------------------------
/src/app/dialogo-confirmacion/dialogo-confirmacion.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { Component, OnInit, Inject } from '@angular/core';
19 | import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
20 | @Component({
21 | selector: 'app-dialogo-confirmacion',
22 | templateUrl: './dialogo-confirmacion.component.html',
23 | styleUrls: ['./dialogo-confirmacion.component.css']
24 | })
25 | export class DialogoConfirmacionComponent implements OnInit {
26 |
27 | constructor(
28 | public dialogo: MatDialogRef,
29 | @Inject(MAT_DIALOG_DATA) public mensaje: string) { }
30 |
31 | cerrarDialogo(): void {
32 | this.dialogo.close(false);
33 | }
34 | confirmado(): void {
35 | this.dialogo.close(true);
36 | }
37 |
38 | ngOnInit() {
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "crud-angular-php-mysql",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e"
11 | },
12 | "private": true,
13 | "dependencies": {
14 | "@angular/animations": "~8.2.13",
15 | "@angular/cdk": "~8.2.3",
16 | "@angular/common": "~8.2.13",
17 | "@angular/compiler": "~8.2.13",
18 | "@angular/core": "~8.2.13",
19 | "@angular/forms": "~8.2.13",
20 | "@angular/material": "^8.2.3",
21 | "@angular/platform-browser": "~8.2.13",
22 | "@angular/platform-browser-dynamic": "~8.2.13",
23 | "@angular/router": "~8.2.13",
24 | "rxjs": "~6.4.0",
25 | "tslib": "^1.10.0",
26 | "zone.js": "~0.9.1"
27 | },
28 | "devDependencies": {
29 | "@angular-devkit/build-angular": "~0.803.17",
30 | "@angular/cli": "~8.3.17",
31 | "@angular/compiler-cli": "~8.2.13",
32 | "@angular/language-service": "~8.2.13",
33 | "@types/node": "~8.9.4",
34 | "@types/jasmine": "~3.3.8",
35 | "@types/jasminewd2": "~2.0.3",
36 | "codelyzer": "^5.0.0",
37 | "jasmine-core": "~3.4.0",
38 | "jasmine-spec-reporter": "~4.2.1",
39 | "karma": "~4.1.0",
40 | "karma-chrome-launcher": "~2.2.0",
41 | "karma-coverage-istanbul-reporter": "~2.0.1",
42 | "karma-jasmine": "~2.0.1",
43 | "karma-jasmine-html-reporter": "^1.4.0",
44 | "protractor": "~5.4.0",
45 | "ts-node": "~7.0.0",
46 | "tslint": "~5.15.0",
47 | "typescript": "~3.5.3"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/app/editar-mascota/editar-mascota.component.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
19 |
20 | import { EditarMascotaComponent } from './editar-mascota.component';
21 |
22 | describe('EditarMascotaComponent', () => {
23 | let component: EditarMascotaComponent;
24 | let fixture: ComponentFixture;
25 |
26 | beforeEach(async(() => {
27 | TestBed.configureTestingModule({
28 | declarations: [ EditarMascotaComponent ]
29 | })
30 | .compileComponents();
31 | }));
32 |
33 | beforeEach(() => {
34 | fixture = TestBed.createComponent(EditarMascotaComponent);
35 | component = fixture.componentInstance;
36 | fixture.detectChanges();
37 | });
38 |
39 | it('should create', () => {
40 | expect(component).toBeTruthy();
41 | });
42 | });
43 |
--------------------------------------------------------------------------------
/src/app/agregar-mascota/agregar-mascota.component.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
19 |
20 | import { AgregarMascotaComponent } from './agregar-mascota.component';
21 |
22 | describe('AgregarMascotaComponent', () => {
23 | let component: AgregarMascotaComponent;
24 | let fixture: ComponentFixture;
25 |
26 | beforeEach(async(() => {
27 | TestBed.configureTestingModule({
28 | declarations: [ AgregarMascotaComponent ]
29 | })
30 | .compileComponents();
31 | }));
32 |
33 | beforeEach(() => {
34 | fixture = TestBed.createComponent(AgregarMascotaComponent);
35 | component = fixture.componentInstance;
36 | fixture.detectChanges();
37 | });
38 |
39 | it('should create', () => {
40 | expect(component).toBeTruthy();
41 | });
42 | });
43 |
--------------------------------------------------------------------------------
/src/app/listar-mascotas/listar-mascotas.component.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
19 |
20 | import { ListarMascotasComponent } from './listar-mascotas.component';
21 |
22 | describe('ListarMascotasComponent', () => {
23 | let component: ListarMascotasComponent;
24 | let fixture: ComponentFixture;
25 |
26 | beforeEach(async(() => {
27 | TestBed.configureTestingModule({
28 | declarations: [ ListarMascotasComponent ]
29 | })
30 | .compileComponents();
31 | }));
32 |
33 | beforeEach(() => {
34 | fixture = TestBed.createComponent(ListarMascotasComponent);
35 | component = fixture.componentInstance;
36 | fixture.detectChanges();
37 | });
38 |
39 | it('should create', () => {
40 | expect(component).toBeTruthy();
41 | });
42 | });
43 |
--------------------------------------------------------------------------------
/src/app/dialogo-confirmacion/dialogo-confirmacion.component.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
19 |
20 | import { DialogoConfirmacionComponent } from './dialogo-confirmacion.component';
21 |
22 | describe('DialogoConfirmacionComponent', () => {
23 | let component: DialogoConfirmacionComponent;
24 | let fixture: ComponentFixture;
25 |
26 | beforeEach(async(() => {
27 | TestBed.configureTestingModule({
28 | declarations: [ DialogoConfirmacionComponent ]
29 | })
30 | .compileComponents();
31 | }));
32 |
33 | beforeEach(() => {
34 | fixture = TestBed.createComponent(DialogoConfirmacionComponent);
35 | component = fixture.componentInstance;
36 | fixture.detectChanges();
37 | });
38 |
39 | it('should create', () => {
40 | expect(component).toBeTruthy();
41 | });
42 | });
43 |
--------------------------------------------------------------------------------
/src/app/listar-mascotas/listar-mascotas.component.html:
--------------------------------------------------------------------------------
1 | Listado de mascotas
2 |
4 |
5 | | Nombre |
6 | {{mascota.nombre}} |
7 |
8 |
9 | Raza |
10 | {{mascota.raza}} |
11 |
12 |
13 | Edad |
14 | {{mascota.edad}} |
15 |
16 |
17 | Editar |
18 |
19 |
20 | edit
21 |
22 | |
23 |
24 |
25 | Eliminar |
26 |
27 |
30 | |
31 |
32 |
33 |
35 |
37 |
--------------------------------------------------------------------------------
/src/app/mascotas.service.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { Injectable } from '@angular/core';
19 | import { HttpClient } from '@angular/common/http';
20 | import { Mascota } from "./mascota"
21 | import { environment } from "../environments/environment"
22 | @Injectable({
23 | providedIn: 'root'
24 | })
25 | export class MascotasService {
26 | baseUrl = environment.baseUrl
27 |
28 | constructor(private http: HttpClient) { }
29 |
30 | getMascotas() {
31 | return this.http.get(`${this.baseUrl}/getAll.php`);
32 | }
33 |
34 | getMascota(id: string | number) {
35 | return this.http.get(`${this.baseUrl}/get.php?idMascota=${id}`);
36 | }
37 |
38 | addMascota(mascota: Mascota) {
39 | return this.http.post(`${this.baseUrl}/post.php`, mascota);
40 | }
41 |
42 | deleteMascota(mascota: Mascota) {
43 | return this.http.delete(`${this.baseUrl}/delete.php?idMascota=${mascota.id}`);
44 | }
45 |
46 | updateMascota(mascota: Mascota) {
47 | return this.http.put(`${this.baseUrl}/update.php`, mascota);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { NgModule } from '@angular/core';
19 | import { Routes, RouterModule } from '@angular/router';
20 | import { AgregarMascotaComponent } from './agregar-mascota/agregar-mascota.component';
21 | import { ListarMascotasComponent } from './listar-mascotas/listar-mascotas.component';
22 | import { EditarMascotaComponent } from './editar-mascota/editar-mascota.component';
23 | import { AcercaDeComponent } from './acerca-de/acerca-de.component';
24 |
25 | const routes: Routes = [
26 | { path: "acerca-de", component: AcercaDeComponent },
27 | { path: "mascotas", component: ListarMascotasComponent },
28 | { path: "mascotas/agregar", component: AgregarMascotaComponent },
29 | { path: "mascotas/editar/:id", component: EditarMascotaComponent },
30 | { path: "", redirectTo: "/mascotas", pathMatch: "full" },// Cuando es la raíz
31 | { path: "**", redirectTo: "/mascotas" }
32 | ];
33 |
34 | @NgModule({
35 | imports: [RouterModule.forRoot(routes)],
36 | exports: [RouterModule]
37 | })
38 | export class AppRoutingModule { }
39 |
--------------------------------------------------------------------------------
/src/app/agregar-mascota/agregar-mascota.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { Component, OnInit } from '@angular/core';
19 | import { Mascota } from '../mascota';
20 | import { MascotasService } from "../mascotas.service"
21 | import { MatSnackBar } from '@angular/material/snack-bar';
22 | import { Router } from '@angular/router';
23 |
24 |
25 | @Component({
26 | selector: 'app-agregar-mascota',
27 | templateUrl: './agregar-mascota.component.html',
28 | styleUrls: ['./agregar-mascota.component.css']
29 | })
30 | export class AgregarMascotaComponent implements OnInit {
31 |
32 | constructor(private mascotasService: MascotasService,
33 | private snackBar: MatSnackBar,
34 | private router: Router,
35 | ) { }
36 |
37 | ngOnInit() {
38 | }
39 | mascotaModel = new Mascota("", "", undefined)
40 |
41 | onSubmit() {
42 | this.mascotasService.addMascota(this.mascotaModel).subscribe(() => {
43 | this.snackBar.open('Mascota guardada', undefined, {
44 | duration: 1500,
45 | });
46 | this.router.navigate(['/mascotas']);
47 | })
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { TestBed, async } from '@angular/core/testing';
19 | import { RouterTestingModule } from '@angular/router/testing';
20 | import { AppComponent } from './app.component';
21 |
22 | describe('AppComponent', () => {
23 | beforeEach(async(() => {
24 | TestBed.configureTestingModule({
25 | imports: [
26 | RouterTestingModule
27 | ],
28 | declarations: [
29 | AppComponent
30 | ],
31 | }).compileComponents();
32 | }));
33 |
34 | it('should create the app', () => {
35 | const fixture = TestBed.createComponent(AppComponent);
36 | const app = fixture.debugElement.componentInstance;
37 | expect(app).toBeTruthy();
38 | });
39 |
40 | it(`should have as title 'crud-angular-php-mysql'`, () => {
41 | const fixture = TestBed.createComponent(AppComponent);
42 | const app = fixture.debugElement.componentInstance;
43 | expect(app.title).toEqual('crud-angular-php-mysql');
44 | });
45 |
46 | it('should render title', () => {
47 | const fixture = TestBed.createComponent(AppComponent);
48 | fixture.detectChanges();
49 | const compiled = fixture.debugElement.nativeElement;
50 | expect(compiled.querySelector('.content span').textContent).toContain('crud-angular-php-mysql app is running!');
51 | });
52 | });
53 |
--------------------------------------------------------------------------------
/src/app/editar-mascota/editar-mascota.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { Component, OnInit } from '@angular/core';
19 | import { Router, ActivatedRoute } from '@angular/router';
20 | import { MascotasService } from "../mascotas.service"
21 | import { Mascota } from '../mascota';
22 | import { MatSnackBar } from '@angular/material/snack-bar';
23 | @Component({
24 | selector: 'app-editar-mascota',
25 | templateUrl: './editar-mascota.component.html',
26 | styleUrls: ['./editar-mascota.component.css']
27 | })
28 | export class EditarMascotaComponent implements OnInit {
29 |
30 | public mascota: Mascota = new Mascota("", "", 0);
31 |
32 | constructor(private route: ActivatedRoute,
33 | private router: Router, private mascotasService: MascotasService,
34 | private snackBar: MatSnackBar) { }
35 |
36 | ngOnInit() {
37 | let idMascota = this.route.snapshot.paramMap.get("id");
38 | this.mascotasService.getMascota(idMascota).subscribe((mascota: Mascota) => this.mascota = mascota)
39 | }
40 |
41 | volver() {
42 | this.router.navigate(['/mascotas']);
43 | }
44 |
45 | onSubmit() {
46 | this.mascotasService.updateMascota(this.mascota).subscribe(() => {
47 | this.snackBar.open('Mascota actualizada', undefined, {
48 | duration: 1500,
49 | });
50 | this.volver();
51 | });
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tslint:recommended",
3 | "rules": {
4 | "array-type": false,
5 | "arrow-parens": false,
6 | "deprecation": {
7 | "severity": "warning"
8 | },
9 | "component-class-suffix": true,
10 | "contextual-lifecycle": true,
11 | "directive-class-suffix": true,
12 | "directive-selector": [
13 | true,
14 | "attribute",
15 | "app",
16 | "camelCase"
17 | ],
18 | "component-selector": [
19 | true,
20 | "element",
21 | "app",
22 | "kebab-case"
23 | ],
24 | "import-blacklist": [
25 | true,
26 | "rxjs/Rx"
27 | ],
28 | "interface-name": false,
29 | "max-classes-per-file": false,
30 | "max-line-length": [
31 | true,
32 | 140
33 | ],
34 | "member-access": false,
35 | "member-ordering": [
36 | true,
37 | {
38 | "order": [
39 | "static-field",
40 | "instance-field",
41 | "static-method",
42 | "instance-method"
43 | ]
44 | }
45 | ],
46 | "no-consecutive-blank-lines": false,
47 | "no-console": [
48 | true,
49 | "debug",
50 | "info",
51 | "time",
52 | "timeEnd",
53 | "trace"
54 | ],
55 | "no-empty": false,
56 | "no-inferrable-types": [
57 | true,
58 | "ignore-params"
59 | ],
60 | "no-non-null-assertion": true,
61 | "no-redundant-jsdoc": true,
62 | "no-switch-case-fall-through": true,
63 | "no-var-requires": false,
64 | "object-literal-key-quotes": [
65 | true,
66 | "as-needed"
67 | ],
68 | "object-literal-sort-keys": false,
69 | "ordered-imports": false,
70 | "quotemark": [
71 | true,
72 | "single"
73 | ],
74 | "trailing-comma": false,
75 | "no-conflicting-lifecycle": true,
76 | "no-host-metadata-property": true,
77 | "no-input-rename": true,
78 | "no-inputs-metadata-property": true,
79 | "no-output-native": true,
80 | "no-output-on-prefix": true,
81 | "no-output-rename": true,
82 | "no-outputs-metadata-property": true,
83 | "template-banana-in-box": true,
84 | "template-no-negated-async": true,
85 | "use-lifecycle-interface": true,
86 | "use-pipe-transform-interface": true
87 | },
88 | "rulesDirectory": [
89 | "codelyzer"
90 | ]
91 | }
--------------------------------------------------------------------------------
/src/app/listar-mascotas/listar-mascotas.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { Component, OnInit } from '@angular/core';
19 | import { MascotasService } from "../mascotas.service"
20 | import { Mascota } from "../mascota"
21 | import { MatDialog } from '@angular/material/dialog';
22 | import { DialogoConfirmacionComponent } from "../dialogo-confirmacion/dialogo-confirmacion.component"
23 | import { MatSnackBar } from '@angular/material/snack-bar';
24 | @Component({
25 | selector: 'app-listar-mascotas',
26 | templateUrl: './listar-mascotas.component.html',
27 | styleUrls: ['./listar-mascotas.component.css']
28 | })
29 | export class ListarMascotasComponent implements OnInit {
30 | public mascotas: Mascota[] = [
31 | new Mascota("Maggie", "Chihuahua", 20)
32 | ];
33 |
34 | constructor(private mascotasService: MascotasService, private dialogo: MatDialog, private snackBar: MatSnackBar) { }
35 |
36 | eliminarMascota(mascota: Mascota) {
37 | this.dialogo
38 | .open(DialogoConfirmacionComponent, {
39 | data: `¿Realmente quieres eliminar a ${mascota.nombre}?`
40 | })
41 | .afterClosed()
42 | .subscribe((confirmado: Boolean) => {
43 | if (!confirmado) return;
44 | this.mascotasService
45 | .deleteMascota(mascota)
46 | .subscribe(() => {
47 | this.obtenerMascotas();
48 | this.snackBar.open('Mascota eliminada', undefined, {
49 | duration: 1500,
50 | });
51 | });
52 | })
53 | }
54 |
55 | ngOnInit() {
56 | this.obtenerMascotas();
57 | }
58 |
59 | obtenerMascotas() {
60 | return this.mascotasService
61 | .getMascotas()
62 | .subscribe((mascotas: Mascota[]) => this.mascotas = mascotas);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
22 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
23 |
24 | /**
25 | * Web Animations `@angular/platform-browser/animations`
26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
28 | */
29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
30 |
31 | /**
32 | * By default, zone.js will patch all possible macroTask and DomEvents
33 | * user can disable parts of macroTask/DomEvents patch by setting following flags
34 | * because those flags need to be set before `zone.js` being loaded, and webpack
35 | * will put import in the top of bundle, so user need to create a separate file
36 | * in this directory (for example: zone-flags.ts), and put the following flags
37 | * into that file, and then add the following code before importing zone.js.
38 | * import './zone-flags.ts';
39 | *
40 | * The flags allowed in zone-flags.ts are listed here.
41 | *
42 | * The following flags will work for all browsers.
43 | *
44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
47 | *
48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
50 | *
51 | * (window as any).__Zone_enable_cross_context_check = true;
52 | *
53 | */
54 |
55 | /***************************************************************************************************
56 | * Zone JS is required by default for Angular itself.
57 | */
58 | import 'zone.js/dist/zone'; // Included with Angular CLI.
59 |
60 |
61 | /***************************************************************************************************
62 | * APPLICATION IMPORTS
63 | */
64 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Programado por Luis Cabrera Benito
4 | ____ _____ _ _ _
5 | | _ \ | __ \ (_) | | |
6 | | |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
7 | | _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
8 | | |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
9 | |____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
10 | __/ | __/ |
11 | |___/ |___/
12 |
13 |
14 | Blog: https://parzibyte.me/blog
15 | Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
16 | Contacto: https://parzibyte.me/blog/contacto/
17 | */
18 | import { BrowserModule } from '@angular/platform-browser';
19 | import { NgModule } from '@angular/core';
20 | import { FormsModule } from '@angular/forms';
21 |
22 | import { AppRoutingModule } from './app-routing.module';
23 | import { AppComponent } from './app.component';
24 | import { AgregarMascotaComponent } from './agregar-mascota/agregar-mascota.component';
25 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
26 | import { MatSidenavModule } from '@angular/material/sidenav';
27 | import { MatToolbarModule } from '@angular/material/toolbar';
28 | import { MatListModule } from '@angular/material/list';
29 | import { MatIconModule } from '@angular/material/icon';
30 | import { MatButtonModule } from '@angular/material/button';
31 | import { MatFormFieldModule } from '@angular/material/form-field';
32 | import { MatExpansionModule } from '@angular/material/expansion';
33 | import { MatInputModule } from '@angular/material';
34 | import { ListarMascotasComponent } from './listar-mascotas/listar-mascotas.component';
35 | import { MatTableModule } from '@angular/material/table';
36 | import { HttpClientModule } from '@angular/common/http';
37 | import { DialogoConfirmacionComponent } from './dialogo-confirmacion/dialogo-confirmacion.component';
38 | import { MatDialogModule } from '@angular/material/dialog';
39 | import { EditarMascotaComponent } from './editar-mascota/editar-mascota.component';
40 | import {MatSnackBarModule} from '@angular/material/snack-bar';
41 | import { AcercaDeComponent } from './acerca-de/acerca-de.component';
42 | @NgModule({
43 | declarations: [
44 | AppComponent,
45 | AgregarMascotaComponent,
46 | ListarMascotasComponent,
47 | DialogoConfirmacionComponent,
48 | EditarMascotaComponent,
49 | AcercaDeComponent
50 | ],
51 | entryComponents: [
52 | DialogoConfirmacionComponent,
53 | ],
54 | imports: [
55 | BrowserModule,
56 | AppRoutingModule,
57 | FormsModule,
58 | BrowserAnimationsModule,
59 | MatSidenavModule,
60 | MatToolbarModule,
61 | MatListModule,
62 | MatIconModule,
63 | MatButtonModule,
64 | MatExpansionModule,
65 | MatFormFieldModule,
66 | MatInputModule,
67 | HttpClientModule,
68 | MatTableModule,
69 | MatDialogModule,
70 | MatSnackBarModule,
71 | ],
72 | providers: [],
73 | bootstrap: [AppComponent]
74 | })
75 | export class AppModule { }
76 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "crud-angular-php-mysql": {
7 | "projectType": "application",
8 | "schematics": {},
9 | "root": "",
10 | "sourceRoot": "src",
11 | "prefix": "app",
12 | "architect": {
13 | "build": {
14 | "builder": "@angular-devkit/build-angular:browser",
15 | "options": {
16 | "outputPath": "dist/crud-angular-php-mysql",
17 | "index": "src/index.html",
18 | "main": "src/main.ts",
19 | "polyfills": "src/polyfills.ts",
20 | "tsConfig": "tsconfig.app.json",
21 | "aot": false,
22 | "assets": [
23 | "src/favicon.ico",
24 | "src/assets"
25 | ],
26 | "styles": [
27 | "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
28 | "src/styles.css"
29 | ],
30 | "scripts": []
31 | },
32 | "configurations": {
33 | "production": {
34 | "fileReplacements": [
35 | {
36 | "replace": "src/environments/environment.ts",
37 | "with": "src/environments/environment.prod.ts"
38 | }
39 | ],
40 | "optimization": true,
41 | "outputHashing": "all",
42 | "sourceMap": false,
43 | "extractCss": true,
44 | "namedChunks": false,
45 | "aot": true,
46 | "extractLicenses": true,
47 | "vendorChunk": false,
48 | "buildOptimizer": true,
49 | "budgets": [
50 | {
51 | "type": "initial",
52 | "maximumWarning": "2mb",
53 | "maximumError": "5mb"
54 | },
55 | {
56 | "type": "anyComponentStyle",
57 | "maximumWarning": "6kb",
58 | "maximumError": "10kb"
59 | }
60 | ]
61 | }
62 | }
63 | },
64 | "serve": {
65 | "builder": "@angular-devkit/build-angular:dev-server",
66 | "options": {
67 | "browserTarget": "crud-angular-php-mysql:build"
68 | },
69 | "configurations": {
70 | "production": {
71 | "browserTarget": "crud-angular-php-mysql:build:production"
72 | }
73 | }
74 | },
75 | "extract-i18n": {
76 | "builder": "@angular-devkit/build-angular:extract-i18n",
77 | "options": {
78 | "browserTarget": "crud-angular-php-mysql:build"
79 | }
80 | },
81 | "test": {
82 | "builder": "@angular-devkit/build-angular:karma",
83 | "options": {
84 | "main": "src/test.ts",
85 | "polyfills": "src/polyfills.ts",
86 | "tsConfig": "tsconfig.spec.json",
87 | "karmaConfig": "karma.conf.js",
88 | "assets": [
89 | "src/favicon.ico",
90 | "src/assets"
91 | ],
92 | "styles": [
93 | "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
94 | "src/styles.css"
95 | ],
96 | "scripts": []
97 | }
98 | },
99 | "lint": {
100 | "builder": "@angular-devkit/build-angular:tslint",
101 | "options": {
102 | "tsConfig": [
103 | "tsconfig.app.json",
104 | "tsconfig.spec.json",
105 | "e2e/tsconfig.json"
106 | ],
107 | "exclude": [
108 | "**/node_modules/**"
109 | ]
110 | }
111 | },
112 | "e2e": {
113 | "builder": "@angular-devkit/build-angular:protractor",
114 | "options": {
115 | "protractorConfig": "e2e/protractor.conf.js",
116 | "devServerTarget": "crud-angular-php-mysql:serve"
117 | },
118 | "configurations": {
119 | "production": {
120 | "devServerTarget": "crud-angular-php-mysql:serve:production"
121 | }
122 | }
123 | }
124 | }
125 | }
126 | },
127 | "defaultProject": "crud-angular-php-mysql"
128 | }
--------------------------------------------------------------------------------