├── .browserslistrc ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.css │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── components │ │ ├── add-tutorial │ │ │ ├── add-tutorial.component.css │ │ │ ├── add-tutorial.component.html │ │ │ ├── add-tutorial.component.spec.ts │ │ │ └── add-tutorial.component.ts │ │ ├── tutorial-details │ │ │ ├── tutorial-details.component.css │ │ │ ├── tutorial-details.component.html │ │ │ ├── tutorial-details.component.spec.ts │ │ │ └── tutorial-details.component.ts │ │ └── tutorials-list │ │ │ ├── tutorials-list.component.css │ │ │ ├── tutorials-list.component.html │ │ │ ├── tutorials-list.component.spec.ts │ │ │ └── tutorials-list.component.ts │ └── services │ │ ├── tutorial.service.spec.ts │ │ └── tutorial.service.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.css └── test.ts ├── tsconfig.app.json ├── tsconfig.base.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json /.browserslistrc: -------------------------------------------------------------------------------- 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 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major version 15 | last 2 iOS major versions 16 | Firefox ESR 17 | not IE 9-11 # For IE 9-11 support, remove 'not'. 18 | -------------------------------------------------------------------------------- /.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 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular 10 CRUD application example with Web API 2 | 3 | For instruction, please visit: 4 | > [Angular 10 CRUD application example with Web API](https://bezkoder.com/angular-10-crud-app/) 5 | 6 | More practice: 7 | > [Angular 10 Pagination example | ngx-pagination](https://github.com/bezkoder/angular-10-pagination-example) 8 | 9 | > [Angular 10 File Upload example with progress bar](https://bezkoder.com/angular-10-file-upload/) 10 | 11 | > [Angular 10 JWT Authentication example with Web Api](https://bezkoder.com/angular-10-jwt-auth/) 12 | 13 | Fullstack with Node.js Express: 14 | > [Angular 10 + Node.js Express + MySQL](https://bezkoder.com/angular-10-node-js-express-mysql/) 15 | 16 | > [Angular 10 + Node.js Express + PostgreSQL](https://bezkoder.com/angular-10-node-express-postgresql/) 17 | 18 | > [Angular 10 + Node.js Express + MongoDB](https://bezkoder.com/angular-10-mongodb-node-express/) 19 | 20 | Fullstack with Spring Boot: 21 | > [Angular 10 + Spring Boot + MySQL](https://bezkoder.com/angular-10-spring-boot-crud/) 22 | 23 | > [Angular 10 + Spring Boot + PostgreSQL](https://bezkoder.com/angular-10-spring-boot-postgresql/) 24 | 25 | > [Angular 10 + Spring Boot + MongoDB](https://bezkoder.com/angular-10-spring-boot-mongodb/) 26 | 27 | Fullstack with Django: 28 | > [Angular 10 + Django Rest Framework](https://bezkoder.com/django-angular-10-crud-rest-framework/) 29 | 30 | > [Angular 10 + Django + MySQL](https://bezkoder.com/django-angular-mysql/) 31 | 32 | > [Angular 10 + Django + PostgreSQL](https://bezkoder.com/django-angular-postgresql/) 33 | 34 | Serverless with Firebase: 35 | > [Angular 10 Firebase CRUD with Realtime Database](https://bezkoder.com/angular-10-firebase-crud/) 36 | 37 | > [Angular 10 Firestore CRUD | AngularFireStore](https://bezkoder.com/angular-10-firestore-crud-angularfire/) 38 | 39 | Integration (run back-end & front-end on same server/port) 40 | > [How to Integrate Angular 10 with Node.js Restful Services](https://bezkoder.com/integrate-angular-10-node-js/) 41 | 42 | > [How to Integrate Angular with Spring Boot Rest API](https://bezkoder.com/integrate-angular-spring-boot/) 43 | 44 | ## Development server 45 | 46 | Run `ng serve --port 8081` for a dev server. Navigate to `http://localhost:8081/`. The app will automatically reload if you change any of the source files. 47 | 48 | ## Code scaffolding 49 | 50 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 51 | 52 | ## Build 53 | 54 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 55 | 56 | ## Running unit tests 57 | 58 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 59 | 60 | ## Running end-to-end tests 61 | 62 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 63 | 64 | ## Further help 65 | 66 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 67 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "Angular10Crud": { 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/Angular10Crud", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": true, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "src/styles.css" 28 | ], 29 | "scripts": [] 30 | }, 31 | "configurations": { 32 | "production": { 33 | "fileReplacements": [ 34 | { 35 | "replace": "src/environments/environment.ts", 36 | "with": "src/environments/environment.prod.ts" 37 | } 38 | ], 39 | "optimization": true, 40 | "outputHashing": "all", 41 | "sourceMap": false, 42 | "extractCss": true, 43 | "namedChunks": false, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | }, 53 | { 54 | "type": "anyComponentStyle", 55 | "maximumWarning": "6kb", 56 | "maximumError": "10kb" 57 | } 58 | ] 59 | } 60 | } 61 | }, 62 | "serve": { 63 | "builder": "@angular-devkit/build-angular:dev-server", 64 | "options": { 65 | "browserTarget": "Angular10Crud:build" 66 | }, 67 | "configurations": { 68 | "production": { 69 | "browserTarget": "Angular10Crud:build:production" 70 | } 71 | } 72 | }, 73 | "extract-i18n": { 74 | "builder": "@angular-devkit/build-angular:extract-i18n", 75 | "options": { 76 | "browserTarget": "Angular10Crud:build" 77 | } 78 | }, 79 | "test": { 80 | "builder": "@angular-devkit/build-angular:karma", 81 | "options": { 82 | "main": "src/test.ts", 83 | "polyfills": "src/polyfills.ts", 84 | "tsConfig": "tsconfig.spec.json", 85 | "karmaConfig": "karma.conf.js", 86 | "assets": [ 87 | "src/favicon.ico", 88 | "src/assets" 89 | ], 90 | "styles": [ 91 | "src/styles.css" 92 | ], 93 | "scripts": [] 94 | } 95 | }, 96 | "lint": { 97 | "builder": "@angular-devkit/build-angular:tslint", 98 | "options": { 99 | "tsConfig": [ 100 | "tsconfig.app.json", 101 | "tsconfig.spec.json", 102 | "e2e/tsconfig.json" 103 | ], 104 | "exclude": [ 105 | "**/node_modules/**" 106 | ] 107 | } 108 | }, 109 | "e2e": { 110 | "builder": "@angular-devkit/build-angular:protractor", 111 | "options": { 112 | "protractorConfig": "e2e/protractor.conf.js", 113 | "devServerTarget": "Angular10Crud:serve" 114 | }, 115 | "configurations": { 116 | "production": { 117 | "devServerTarget": "Angular10Crud:serve:production" 118 | } 119 | } 120 | } 121 | } 122 | }}, 123 | "defaultProject": "Angular10Crud" 124 | } 125 | -------------------------------------------------------------------------------- /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, StacktraceOption } = 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({ 31 | spec: { 32 | displayStacktrace: StacktraceOption.PRETTY 33 | } 34 | })); 35 | } 36 | }; -------------------------------------------------------------------------------- /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('Angular10Crud 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 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(): Promise { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "../out-tsc/e2e", 6 | "module": "commonjs", 7 | "target": "es2018", 8 | "types": [ 9 | "jasmine", 10 | "jasminewd2", 11 | "node" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /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/Angular10Crud'), 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular10-crud", 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": "~10.0.0", 15 | "@angular/common": "~10.0.0", 16 | "@angular/compiler": "~10.0.0", 17 | "@angular/core": "~10.0.0", 18 | "@angular/forms": "~10.0.0", 19 | "@angular/platform-browser": "~10.0.0", 20 | "@angular/platform-browser-dynamic": "~10.0.0", 21 | "@angular/router": "~10.0.0", 22 | "rxjs": "~6.5.5", 23 | "tslib": "^2.0.0", 24 | "zone.js": "~0.10.3" 25 | }, 26 | "devDependencies": { 27 | "@angular-devkit/build-angular": "~0.1000.0", 28 | "@angular/cli": "~10.0.0", 29 | "@angular/compiler-cli": "~10.0.0", 30 | "@types/node": "^12.11.1", 31 | "@types/jasmine": "~3.5.0", 32 | "@types/jasminewd2": "~2.0.3", 33 | "codelyzer": "^6.0.0-next.1", 34 | "jasmine-core": "~3.5.0", 35 | "jasmine-spec-reporter": "~5.0.0", 36 | "karma": "~5.0.0", 37 | "karma-chrome-launcher": "~3.1.0", 38 | "karma-coverage-istanbul-reporter": "~3.0.2", 39 | "karma-jasmine": "~3.3.0", 40 | "karma-jasmine-html-reporter": "^1.5.0", 41 | "protractor": "~7.0.0", 42 | "ts-node": "~8.3.0", 43 | "tslint": "~6.1.0", 44 | "typescript": "~3.9.5" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { TutorialsListComponent } from './components/tutorials-list/tutorials-list.component'; 4 | import { TutorialDetailsComponent } from './components/tutorial-details/tutorial-details.component'; 5 | import { AddTutorialComponent } from './components/add-tutorial/add-tutorial.component'; 6 | 7 | const routes: Routes = [ 8 | { path: '', redirectTo: 'tutorials', pathMatch: 'full' }, 9 | { path: 'tutorials', component: TutorialsListComponent }, 10 | { path: 'tutorials/:id', component: TutorialDetailsComponent }, 11 | { path: 'add', component: AddTutorialComponent } 12 | ]; 13 | 14 | @NgModule({ 15 | imports: [RouterModule.forRoot(routes)], 16 | exports: [RouterModule] 17 | }) 18 | export class AppRoutingModule { } 19 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/angular-10-crud-app/4ed18b9b353eb817daf76f34df575625e0220b73/src/app/app.component.css -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 | 13 | 14 |
15 | 16 |
17 |
18 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'Angular10Crud'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('Angular10Crud'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('Angular10Crud app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'Angular10Crud'; 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { HttpClientModule } from '@angular/common/http'; 5 | 6 | import { AppRoutingModule } from './app-routing.module'; 7 | import { AppComponent } from './app.component'; 8 | import { AddTutorialComponent } from './components/add-tutorial/add-tutorial.component'; 9 | import { TutorialDetailsComponent } from './components/tutorial-details/tutorial-details.component'; 10 | import { TutorialsListComponent } from './components/tutorials-list/tutorials-list.component'; 11 | 12 | @NgModule({ 13 | declarations: [ 14 | AppComponent, 15 | AddTutorialComponent, 16 | TutorialDetailsComponent, 17 | TutorialsListComponent 18 | ], 19 | imports: [ 20 | BrowserModule, 21 | AppRoutingModule, 22 | FormsModule, 23 | HttpClientModule 24 | ], 25 | providers: [], 26 | bootstrap: [AppComponent] 27 | }) 28 | export class AppModule { } 29 | -------------------------------------------------------------------------------- /src/app/components/add-tutorial/add-tutorial.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/angular-10-crud-app/4ed18b9b353eb817daf76f34df575625e0220b73/src/app/components/add-tutorial/add-tutorial.component.css -------------------------------------------------------------------------------- /src/app/components/add-tutorial/add-tutorial.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | 6 | 14 |
15 | 16 |
17 | 18 | 25 |
26 | 27 | 28 |
29 | 30 |
31 |

You submitted successfully!

32 | 33 |
34 |
35 |
36 | -------------------------------------------------------------------------------- /src/app/components/add-tutorial/add-tutorial.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AddTutorialComponent } from './add-tutorial.component'; 4 | 5 | describe('AddTutorialComponent', () => { 6 | let component: AddTutorialComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AddTutorialComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AddTutorialComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/components/add-tutorial/add-tutorial.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { TutorialService } from 'src/app/services/tutorial.service'; 3 | 4 | @Component({ 5 | selector: 'app-add-tutorial', 6 | templateUrl: './add-tutorial.component.html', 7 | styleUrls: ['./add-tutorial.component.css'] 8 | }) 9 | export class AddTutorialComponent implements OnInit { 10 | tutorial = { 11 | title: '', 12 | description: '', 13 | published: false 14 | }; 15 | submitted = false; 16 | 17 | constructor(private tutorialService: TutorialService) { } 18 | 19 | ngOnInit(): void { 20 | } 21 | 22 | saveTutorial(): void { 23 | const data = { 24 | title: this.tutorial.title, 25 | description: this.tutorial.description 26 | }; 27 | 28 | this.tutorialService.create(data) 29 | .subscribe( 30 | response => { 31 | console.log(response); 32 | this.submitted = true; 33 | }, 34 | error => { 35 | console.log(error); 36 | }); 37 | } 38 | 39 | newTutorial(): void { 40 | this.submitted = false; 41 | this.tutorial = { 42 | title: '', 43 | description: '', 44 | published: false 45 | }; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/app/components/tutorial-details/tutorial-details.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/angular-10-crud-app/4ed18b9b353eb817daf76f34df575625e0220b73/src/app/components/tutorial-details/tutorial-details.component.css -------------------------------------------------------------------------------- /src/app/components/tutorial-details/tutorial-details.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Tutorial

4 |
5 |
6 | 7 | 14 |
15 |
16 | 17 | 24 |
25 | 26 |
27 | 28 | {{ currentTutorial.published ? "Published" : "Pending" }} 29 |
30 |
31 | 32 | 39 | 46 | 47 | 50 | 51 | 58 |

{{ message }}

59 |
60 | 61 |
62 |
63 |

Cannot access this Tutorial...

64 |
65 |
66 | -------------------------------------------------------------------------------- /src/app/components/tutorial-details/tutorial-details.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { TutorialDetailsComponent } from './tutorial-details.component'; 4 | 5 | describe('TutorialDetailsComponent', () => { 6 | let component: TutorialDetailsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ TutorialDetailsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(TutorialDetailsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/components/tutorial-details/tutorial-details.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { TutorialService } from 'src/app/services/tutorial.service'; 3 | import { ActivatedRoute, Router } from '@angular/router'; 4 | 5 | @Component({ 6 | selector: 'app-tutorial-details', 7 | templateUrl: './tutorial-details.component.html', 8 | styleUrls: ['./tutorial-details.component.css'] 9 | }) 10 | export class TutorialDetailsComponent implements OnInit { 11 | currentTutorial = null; 12 | message = ''; 13 | 14 | constructor( 15 | private tutorialService: TutorialService, 16 | private route: ActivatedRoute, 17 | private router: Router) { } 18 | 19 | ngOnInit(): void { 20 | this.message = ''; 21 | this.getTutorial(this.route.snapshot.paramMap.get('id')); 22 | } 23 | 24 | getTutorial(id): void { 25 | this.tutorialService.get(id) 26 | .subscribe( 27 | data => { 28 | this.currentTutorial = data; 29 | console.log(data); 30 | }, 31 | error => { 32 | console.log(error); 33 | }); 34 | } 35 | 36 | updatePublished(status): void { 37 | const data = { 38 | title: this.currentTutorial.title, 39 | description: this.currentTutorial.description, 40 | published: status 41 | }; 42 | 43 | this.tutorialService.update(this.currentTutorial.id, data) 44 | .subscribe( 45 | response => { 46 | this.currentTutorial.published = status; 47 | console.log(response); 48 | }, 49 | error => { 50 | console.log(error); 51 | }); 52 | } 53 | 54 | updateTutorial(): void { 55 | this.tutorialService.update(this.currentTutorial.id, this.currentTutorial) 56 | .subscribe( 57 | response => { 58 | console.log(response); 59 | this.message = 'The tutorial was updated successfully!'; 60 | }, 61 | error => { 62 | console.log(error); 63 | }); 64 | } 65 | 66 | deleteTutorial(): void { 67 | this.tutorialService.delete(this.currentTutorial.id) 68 | .subscribe( 69 | response => { 70 | console.log(response); 71 | this.router.navigate(['/tutorials']); 72 | }, 73 | error => { 74 | console.log(error); 75 | }); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/app/components/tutorials-list/tutorials-list.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/angular-10-crud-app/4ed18b9b353eb817daf76f34df575625e0220b73/src/app/components/tutorials-list/tutorials-list.component.css -------------------------------------------------------------------------------- /src/app/components/tutorials-list/tutorials-list.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 10 |
11 | 18 |
19 |
20 |
21 |
22 |

Tutorials List

23 |
    24 |
  • 30 | {{ tutorial.title }} 31 |
  • 32 |
33 | 34 | 37 |
38 |
39 |
40 |

Tutorial

41 |
42 | {{ currentTutorial.title }} 43 |
44 |
45 | 46 | {{ currentTutorial.description }} 47 |
48 |
49 | 50 | {{ currentTutorial.published ? "Published" : "Pending" }} 51 |
52 | 53 | 54 | Edit 55 | 56 |
57 | 58 |
59 |
60 |

Please click on a Tutorial...

61 |
62 |
63 |
64 | -------------------------------------------------------------------------------- /src/app/components/tutorials-list/tutorials-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { TutorialsListComponent } from './tutorials-list.component'; 4 | 5 | describe('TutorialsListComponent', () => { 6 | let component: TutorialsListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ TutorialsListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(TutorialsListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/components/tutorials-list/tutorials-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { TutorialService } from 'src/app/services/tutorial.service'; 3 | 4 | @Component({ 5 | selector: 'app-tutorials-list', 6 | templateUrl: './tutorials-list.component.html', 7 | styleUrls: ['./tutorials-list.component.css'] 8 | }) 9 | export class TutorialsListComponent implements OnInit { 10 | 11 | tutorials: any; 12 | currentTutorial = null; 13 | currentIndex = -1; 14 | title = ''; 15 | 16 | constructor(private tutorialService: TutorialService) { } 17 | 18 | ngOnInit(): void { 19 | this.retrieveTutorials(); 20 | } 21 | 22 | retrieveTutorials(): void { 23 | this.tutorialService.getAll() 24 | .subscribe( 25 | data => { 26 | this.tutorials = data; 27 | console.log(data); 28 | }, 29 | error => { 30 | console.log(error); 31 | }); 32 | } 33 | 34 | refreshList(): void { 35 | this.retrieveTutorials(); 36 | this.currentTutorial = null; 37 | this.currentIndex = -1; 38 | } 39 | 40 | setActiveTutorial(tutorial, index): void { 41 | this.currentTutorial = tutorial; 42 | this.currentIndex = index; 43 | } 44 | 45 | removeAllTutorials(): void { 46 | this.tutorialService.deleteAll() 47 | .subscribe( 48 | response => { 49 | console.log(response); 50 | this.refreshList(); 51 | }, 52 | error => { 53 | console.log(error); 54 | }); 55 | } 56 | 57 | searchTitle(): void { 58 | this.tutorialService.findByTitle(this.title) 59 | .subscribe( 60 | data => { 61 | this.tutorials = data; 62 | console.log(data); 63 | }, 64 | error => { 65 | console.log(error); 66 | }); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/app/services/tutorial.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { TutorialService } from './tutorial.service'; 4 | 5 | describe('TutorialService', () => { 6 | let service: TutorialService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(TutorialService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/app/services/tutorial.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Observable } from 'rxjs'; 4 | 5 | const baseUrl = 'http://localhost:8080/api/tutorials'; 6 | 7 | @Injectable({ 8 | providedIn: 'root' 9 | }) 10 | export class TutorialService { 11 | 12 | constructor(private http: HttpClient) { } 13 | 14 | getAll(): Observable { 15 | return this.http.get(baseUrl); 16 | } 17 | 18 | get(id): Observable { 19 | return this.http.get(`${baseUrl}/${id}`); 20 | } 21 | 22 | create(data): Observable { 23 | return this.http.post(baseUrl, data); 24 | } 25 | 26 | update(id, data): Observable { 27 | return this.http.put(`${baseUrl}/${id}`, data); 28 | } 29 | 30 | delete(id): Observable { 31 | return this.http.delete(`${baseUrl}/${id}`); 32 | } 33 | 34 | deleteAll(): Observable { 35 | return this.http.delete(baseUrl); 36 | } 37 | 38 | findByTitle(title): Observable { 39 | return this.http.get(`${baseUrl}?title=${title}`); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/angular-10-crud-app/4ed18b9b353eb817daf76f34df575625e0220b73/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /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 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/angular-10-crud-app/4ed18b9b353eb817daf76f34df575625e0220b73/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angular10Crud 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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'; 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/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /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: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "sourceMap": true, 8 | "declaration": false, 9 | "downlevelIteration": true, 10 | "experimentalDecorators": true, 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "module": "es2020", 15 | "lib": [ 16 | "es2018", 17 | "dom" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | /* 2 | This is a "Solution Style" tsconfig.json file, and is used by editors and TypeScript’s language server to improve development experience. 3 | It is not intended to be used to perform a compilation. 4 | 5 | To learn more about this file see: https://angular.io/config/solution-tsconfig. 6 | */ 7 | { 8 | "files": [], 9 | "references": [ 10 | { 11 | "path": "./tsconfig.app.json" 12 | }, 13 | { 14 | "path": "./tsconfig.spec.json" 15 | }, 16 | { 17 | "path": "./e2e/tsconfig.json" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 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 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "align": { 5 | "options": [ 6 | "parameters", 7 | "statements" 8 | ] 9 | }, 10 | "array-type": false, 11 | "arrow-return-shorthand": true, 12 | "curly": true, 13 | "deprecation": { 14 | "severity": "warning" 15 | }, 16 | "component-class-suffix": true, 17 | "contextual-lifecycle": true, 18 | "directive-class-suffix": true, 19 | "directive-selector": [ 20 | true, 21 | "attribute", 22 | "app", 23 | "camelCase" 24 | ], 25 | "component-selector": [ 26 | true, 27 | "element", 28 | "app", 29 | "kebab-case" 30 | ], 31 | "eofline": true, 32 | "import-blacklist": [ 33 | true, 34 | "rxjs/Rx" 35 | ], 36 | "import-spacing": true, 37 | "indent": { 38 | "options": [ 39 | "spaces" 40 | ] 41 | }, 42 | "max-classes-per-file": false, 43 | "max-line-length": [ 44 | true, 45 | 140 46 | ], 47 | "member-ordering": [ 48 | true, 49 | { 50 | "order": [ 51 | "static-field", 52 | "instance-field", 53 | "static-method", 54 | "instance-method" 55 | ] 56 | } 57 | ], 58 | "no-console": [ 59 | true, 60 | "debug", 61 | "info", 62 | "time", 63 | "timeEnd", 64 | "trace" 65 | ], 66 | "no-empty": false, 67 | "no-inferrable-types": [ 68 | true, 69 | "ignore-params" 70 | ], 71 | "no-non-null-assertion": true, 72 | "no-redundant-jsdoc": true, 73 | "no-switch-case-fall-through": true, 74 | "no-var-requires": false, 75 | "object-literal-key-quotes": [ 76 | true, 77 | "as-needed" 78 | ], 79 | "quotemark": [ 80 | true, 81 | "single" 82 | ], 83 | "semicolon": { 84 | "options": [ 85 | "always" 86 | ] 87 | }, 88 | "space-before-function-paren": { 89 | "options": { 90 | "anonymous": "never", 91 | "asyncArrow": "always", 92 | "constructor": "never", 93 | "method": "never", 94 | "named": "never" 95 | } 96 | }, 97 | "typedef": [ 98 | true, 99 | "call-signature" 100 | ], 101 | "typedef-whitespace": { 102 | "options": [ 103 | { 104 | "call-signature": "nospace", 105 | "index-signature": "nospace", 106 | "parameter": "nospace", 107 | "property-declaration": "nospace", 108 | "variable-declaration": "nospace" 109 | }, 110 | { 111 | "call-signature": "onespace", 112 | "index-signature": "onespace", 113 | "parameter": "onespace", 114 | "property-declaration": "onespace", 115 | "variable-declaration": "onespace" 116 | } 117 | ] 118 | }, 119 | "variable-name": { 120 | "options": [ 121 | "ban-keywords", 122 | "check-format", 123 | "allow-pascal-case" 124 | ] 125 | }, 126 | "whitespace": { 127 | "options": [ 128 | "check-branch", 129 | "check-decl", 130 | "check-operator", 131 | "check-separator", 132 | "check-type", 133 | "check-typecast" 134 | ] 135 | }, 136 | "no-conflicting-lifecycle": true, 137 | "no-host-metadata-property": true, 138 | "no-input-rename": true, 139 | "no-inputs-metadata-property": true, 140 | "no-output-native": true, 141 | "no-output-on-prefix": true, 142 | "no-output-rename": true, 143 | "no-outputs-metadata-property": true, 144 | "template-banana-in-box": true, 145 | "template-no-negated-async": true, 146 | "use-lifecycle-interface": true, 147 | "use-pipe-transform-interface": true 148 | }, 149 | "rulesDirectory": [ 150 | "codelyzer" 151 | ] 152 | } --------------------------------------------------------------------------------