├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── angular.json ├── app.js ├── bin └── www ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.e2e.json ├── models └── Book.js ├── package-lock.json ├── package.json ├── routes └── book.js ├── src ├── app │ ├── api.service.spec.ts │ ├── api.service.ts │ ├── app.component.css │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── book-create │ │ ├── book-create.component.css │ │ ├── book-create.component.html │ │ ├── book-create.component.spec.ts │ │ └── book-create.component.ts │ ├── book-detail │ │ ├── book-detail.component.css │ │ ├── book-detail.component.html │ │ ├── book-detail.component.spec.ts │ │ └── book-detail.component.ts │ ├── book-edit │ │ ├── book-edit.component.css │ │ ├── book-edit.component.html │ │ ├── book-edit.component.spec.ts │ │ └── book-edit.component.ts │ └── book │ │ ├── book.component.css │ │ ├── book.component.html │ │ ├── book.component.spec.ts │ │ └── book.component.ts ├── assets │ └── .gitkeep ├── browserslist ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── karma.conf.js ├── main.ts ├── polyfills.ts ├── styles.css ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── tslint.json ├── tsconfig.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://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 | -------------------------------------------------------------------------------- /.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 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Didin Jamaludin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MEAN Stack Angular 6 CRUD Web Application 2 | 3 | This source codes if part of [MEAN Stack Angular 6 CRUD Web Application](https://www.djamware.com/post/5b00bb9180aca726dee1fd6d/mean-stack-angular-6-crud-web-application) tutorial. 4 | 5 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.0.1. 6 | 7 | ## Development server 8 | 9 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 10 | 11 | ## Code scaffolding 12 | 13 | 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`. 14 | 15 | ## Build 16 | 17 | 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. 18 | 19 | ## Running unit tests 20 | 21 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 22 | 23 | ## Running end-to-end tests 24 | 25 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 26 | 27 | ## Further help 28 | 29 | 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). 30 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "mean-angular6": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/mean-angular6", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | { 27 | "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css" 28 | }, 29 | "src/styles.css" 30 | ], 31 | "scripts": [] 32 | }, 33 | "configurations": { 34 | "production": { 35 | "fileReplacements": [ 36 | { 37 | "replace": "src/environments/environment.ts", 38 | "with": "src/environments/environment.prod.ts" 39 | } 40 | ], 41 | "optimization": true, 42 | "outputHashing": "all", 43 | "sourceMap": false, 44 | "extractCss": true, 45 | "namedChunks": false, 46 | "aot": true, 47 | "extractLicenses": true, 48 | "vendorChunk": false, 49 | "buildOptimizer": true 50 | } 51 | } 52 | }, 53 | "serve": { 54 | "builder": "@angular-devkit/build-angular:dev-server", 55 | "options": { 56 | "browserTarget": "mean-angular6:build" 57 | }, 58 | "configurations": { 59 | "production": { 60 | "browserTarget": "mean-angular6:build:production" 61 | } 62 | } 63 | }, 64 | "extract-i18n": { 65 | "builder": "@angular-devkit/build-angular:extract-i18n", 66 | "options": { 67 | "browserTarget": "mean-angular6:build" 68 | } 69 | }, 70 | "test": { 71 | "builder": "@angular-devkit/build-angular:karma", 72 | "options": { 73 | "main": "src/test.ts", 74 | "polyfills": "src/polyfills.ts", 75 | "tsConfig": "src/tsconfig.spec.json", 76 | "karmaConfig": "src/karma.conf.js", 77 | "styles": [ 78 | { 79 | "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css" 80 | }, 81 | "src/styles.css" 82 | ], 83 | "scripts": [], 84 | "assets": [ 85 | "src/favicon.ico", 86 | "src/assets" 87 | ] 88 | } 89 | }, 90 | "lint": { 91 | "builder": "@angular-devkit/build-angular:tslint", 92 | "options": { 93 | "tsConfig": [ 94 | "src/tsconfig.app.json", 95 | "src/tsconfig.spec.json" 96 | ], 97 | "exclude": [ 98 | "**/node_modules/**" 99 | ] 100 | } 101 | } 102 | } 103 | }, 104 | "mean-angular6-e2e": { 105 | "root": "e2e/", 106 | "projectType": "application", 107 | "architect": { 108 | "e2e": { 109 | "builder": "@angular-devkit/build-angular:protractor", 110 | "options": { 111 | "protractorConfig": "e2e/protractor.conf.js", 112 | "devServerTarget": "mean-angular6:serve" 113 | } 114 | }, 115 | "lint": { 116 | "builder": "@angular-devkit/build-angular:tslint", 117 | "options": { 118 | "tsConfig": "e2e/tsconfig.e2e.json", 119 | "exclude": [ 120 | "**/node_modules/**" 121 | ] 122 | } 123 | } 124 | } 125 | } 126 | }, 127 | "defaultProject": "mean-angular6" 128 | } -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | var createError = require('http-errors'); 2 | var express = require('express'); 3 | var path = require('path'); 4 | var favicon = require('serve-favicon'); 5 | var logger = require('morgan'); 6 | 7 | var mongoose = require('mongoose'); 8 | mongoose.connect('mongodb://localhost/mean-angular6') 9 | .then(() => console.log('connection succesful')) 10 | .catch((err) => console.error(err)); 11 | 12 | var apiRouter = require('./routes/book'); 13 | 14 | var app = express(); 15 | 16 | app.use(logger('dev')); 17 | app.use(express.json()); 18 | app.use(express.urlencoded({ extended: false })); 19 | app.use(express.static(path.join(__dirname, 'dist/mean-angular6'))); 20 | app.use('/books', express.static(path.join(__dirname, 'dist/mean-angular6'))); 21 | app.use('/book-details/:id', express.static(path.join(__dirname, 'dist/mean-angular6'))); 22 | app.use('/book-create', express.static(path.join(__dirname, 'dist/mean-angular6'))); 23 | app.use('/book-edit/:id', express.static(path.join(__dirname, 'dist/mean-angular6'))); 24 | app.use('/api', apiRouter); 25 | 26 | // catch 404 and forward to error handler 27 | app.use(function(req, res, next) { 28 | next(createError(404)); 29 | }); 30 | 31 | // error handler 32 | app.use(function(err, req, res, next) { 33 | // set locals, only providing error in development 34 | res.locals.message = err.message; 35 | res.locals.error = req.app.get('env') === 'development' ? err : {}; 36 | 37 | // render the error page 38 | res.status(err.status || 500); 39 | res.send(err.status); 40 | }); 41 | 42 | module.exports = app; 43 | -------------------------------------------------------------------------------- /bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('mean-angular6:server'); 9 | var http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | var port = normalizePort(process.env.PORT || '3000'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | var server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | var port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | var bind = typeof port === 'string' 62 | ? 'Pipe ' + port 63 | : 'Port ' + port; 64 | 65 | // handle specific listen errors with friendly messages 66 | switch (error.code) { 67 | case 'EACCES': 68 | console.error(bind + ' requires elevated privileges'); 69 | process.exit(1); 70 | break; 71 | case 'EADDRINUSE': 72 | console.error(bind + ' is already in use'); 73 | process.exit(1); 74 | break; 75 | default: 76 | throw error; 77 | } 78 | } 79 | 80 | /** 81 | * Event listener for HTTP server "listening" event. 82 | */ 83 | 84 | function onListening() { 85 | var addr = server.address(); 86 | var bind = typeof addr === 'string' 87 | ? 'pipe ' + addr 88 | : 'port ' + addr.port; 89 | debug('Listening on ' + bind); 90 | } 91 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /models/Book.js: -------------------------------------------------------------------------------- 1 | var mongoose = require('mongoose'); 2 | 3 | var BookSchema = new mongoose.Schema({ 4 | isbn: String, 5 | title: String, 6 | author: String, 7 | description: String, 8 | published_year: String, 9 | publisher: String, 10 | updated_date: { type: Date, default: Date.now }, 11 | }); 12 | 13 | module.exports = mongoose.model('Book', BookSchema); 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mean-angular6", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng build && node ./bin/www", 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": "^6.0.0", 15 | "@angular/common": "^6.0.0", 16 | "@angular/compiler": "^6.0.0", 17 | "@angular/core": "^6.0.0", 18 | "@angular/forms": "^6.0.0", 19 | "@angular/http": "^6.0.0", 20 | "@angular/material": "^6.0.2", 21 | "@angular/platform-browser": "^6.0.0", 22 | "@angular/platform-browser-dynamic": "^6.0.0", 23 | "@angular/router": "^6.0.0", 24 | "body-parser": "^1.18.3", 25 | "core-js": "^2.5.4", 26 | "express": "^4.16.3", 27 | "http-errors": "^1.6.3", 28 | "mongoose": "^5.1.1", 29 | "morgan": "^1.9.0", 30 | "rxjs": "^6.0.0", 31 | "serve-favicon": "^2.5.0", 32 | "zone.js": "^0.8.26", 33 | "@angular/cdk": "^6.0.0" 34 | }, 35 | "devDependencies": { 36 | "@angular-devkit/build-angular": "~0.6.1", 37 | "@angular/cli": "^6.0.0", 38 | "@angular/compiler-cli": "^6.0.0", 39 | "@angular/language-service": "^6.0.0", 40 | "@types/jasmine": "~2.8.6", 41 | "@types/jasminewd2": "~2.0.3", 42 | "@types/node": "~8.9.4", 43 | "codelyzer": "~4.2.1", 44 | "jasmine-core": "~2.99.1", 45 | "jasmine-spec-reporter": "~4.2.1", 46 | "karma": "~1.7.1", 47 | "karma-chrome-launcher": "~2.2.0", 48 | "karma-coverage-istanbul-reporter": "~1.4.2", 49 | "karma-jasmine": "^1.1.2", 50 | "karma-jasmine-html-reporter": "^0.2.2", 51 | "protractor": "~5.3.0", 52 | "ts-node": "~5.0.1", 53 | "tslint": "~5.9.1", 54 | "typescript": "^2.7.2" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /routes/book.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | var mongoose = require('mongoose'); 4 | var Book = require('../models/Book.js'); 5 | 6 | /* GET ALL BOOKS */ 7 | router.get('/', function(req, res, next) { 8 | Book.find(function (err, products) { 9 | if (err) return next(err); 10 | res.json(products); 11 | }); 12 | }); 13 | 14 | /* GET SINGLE BOOK BY ID */ 15 | router.get('/:id', function(req, res, next) { 16 | Book.findById(req.params.id, function (err, post) { 17 | if (err) return next(err); 18 | res.json(post); 19 | }); 20 | }); 21 | 22 | /* SAVE BOOK */ 23 | router.post('/', function(req, res, next) { 24 | Book.create(req.body, function (err, post) { 25 | if (err) return next(err); 26 | res.json(post); 27 | }); 28 | }); 29 | 30 | /* UPDATE BOOK */ 31 | router.put('/:id', function(req, res, next) { 32 | Book.findByIdAndUpdate(req.params.id, req.body, function (err, post) { 33 | if (err) return next(err); 34 | res.json(post); 35 | }); 36 | }); 37 | 38 | /* DELETE BOOK */ 39 | router.delete('/:id', function(req, res, next) { 40 | Book.findByIdAndRemove(req.params.id, req.body, function (err, post) { 41 | if (err) return next(err); 42 | res.json(post); 43 | }); 44 | }); 45 | 46 | module.exports = router; 47 | -------------------------------------------------------------------------------- /src/app/api.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { ApiService } from './api.service'; 4 | 5 | describe('ApiService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [ApiService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([ApiService], (service: ApiService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/api.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Observable, of, throwError } from 'rxjs'; 3 | import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http'; 4 | import { catchError, tap, map } from 'rxjs/operators'; 5 | 6 | const httpOptions = { 7 | headers: new HttpHeaders({'Content-Type': 'application/json'}) 8 | }; 9 | const apiUrl = "/api"; 10 | 11 | @Injectable({ 12 | providedIn: 'root' 13 | }) 14 | export class ApiService { 15 | 16 | constructor(private http: HttpClient) { } 17 | 18 | private handleError(error: HttpErrorResponse) { 19 | if (error.error instanceof ErrorEvent) { 20 | // A client-side or network error occurred. Handle it accordingly. 21 | console.error('An error occurred:', error.error.message); 22 | } else { 23 | // The backend returned an unsuccessful response code. 24 | // The response body may contain clues as to what went wrong, 25 | console.error( 26 | `Backend returned code ${error.status}, ` + 27 | `body was: ${error.error}`); 28 | } 29 | // return an observable with a user-facing error message 30 | return throwError('Something bad happened; please try again later.'); 31 | }; 32 | 33 | private extractData(res: Response) { 34 | let body = res; 35 | return body || { }; 36 | } 37 | 38 | getBooks(): Observable { 39 | return this.http.get(apiUrl, httpOptions).pipe( 40 | map(this.extractData), 41 | catchError(this.handleError)); 42 | } 43 | 44 | getBook(id: string): Observable { 45 | const url = `${apiUrl}/${id}`; 46 | return this.http.get(url, httpOptions).pipe( 47 | map(this.extractData), 48 | catchError(this.handleError)); 49 | } 50 | 51 | postBook(data): Observable { 52 | return this.http.post(apiUrl, data, httpOptions) 53 | .pipe( 54 | catchError(this.handleError) 55 | ); 56 | } 57 | 58 | updateBook(id: string, data): Observable { 59 | const url = `${apiUrl}/${id}`; 60 | return this.http.put(url, data, httpOptions) 61 | .pipe( 62 | catchError(this.handleError) 63 | ); 64 | } 65 | 66 | deleteBook(id: string): Observable<{}> { 67 | const url = `${apiUrl}/${id}`; 68 | return this.http.delete(url, httpOptions) 69 | .pipe( 70 | catchError(this.handleError) 71 | ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular6-crud-example/0efdf5cd350f7db35da3d5b21f1f5e7bed1abcfc/src/app/app.component.css -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | describe('AppComponent', () => { 4 | beforeEach(async(() => { 5 | TestBed.configureTestingModule({ 6 | declarations: [ 7 | AppComponent 8 | ], 9 | }).compileComponents(); 10 | })); 11 | it('should create the app', async(() => { 12 | const fixture = TestBed.createComponent(AppComponent); 13 | const app = fixture.debugElement.componentInstance; 14 | expect(app).toBeTruthy(); 15 | })); 16 | it(`should have as title 'app'`, async(() => { 17 | const fixture = TestBed.createComponent(AppComponent); 18 | const app = fixture.debugElement.componentInstance; 19 | expect(app.title).toEqual('app'); 20 | })); 21 | it('should render title in a h1 tag', async(() => { 22 | const fixture = TestBed.createComponent(AppComponent); 23 | fixture.detectChanges(); 24 | const compiled = fixture.debugElement.nativeElement; 25 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); 26 | })); 27 | }); 28 | -------------------------------------------------------------------------------- /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 = 'app'; 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 4 | import { HttpClientModule } from '@angular/common/http'; 5 | 6 | import { AppComponent } from './app.component'; 7 | import { RouterModule, Routes } from '@angular/router'; 8 | import { BookComponent } from './book/book.component'; 9 | import { BookDetailComponent } from './book-detail/book-detail.component'; 10 | import { BookCreateComponent } from './book-create/book-create.component'; 11 | import { BookEditComponent } from './book-edit/book-edit.component'; 12 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 13 | 14 | import { 15 | MatInputModule, 16 | MatPaginatorModule, 17 | MatProgressSpinnerModule, 18 | MatSortModule, 19 | MatTableModule, 20 | MatIconModule, 21 | MatButtonModule, 22 | MatCardModule, 23 | MatFormFieldModule } from "@angular/material"; 24 | 25 | const appRoutes: Routes = [ 26 | { 27 | path: 'books', 28 | component: BookComponent, 29 | data: { title: 'Book List' } 30 | }, 31 | { 32 | path: 'book-details/:id', 33 | component: BookDetailComponent, 34 | data: { title: 'Book Details' } 35 | }, 36 | { 37 | path: 'book-create', 38 | component: BookCreateComponent, 39 | data: { title: 'Create Book' } 40 | }, 41 | { 42 | path: 'book-edit/:id', 43 | component: BookEditComponent, 44 | data: { title: 'Edit Book' } 45 | }, 46 | { path: '', 47 | redirectTo: '/books', 48 | pathMatch: 'full' 49 | } 50 | ]; 51 | 52 | @NgModule({ 53 | declarations: [ 54 | AppComponent, 55 | BookComponent, 56 | BookDetailComponent, 57 | BookCreateComponent, 58 | BookEditComponent 59 | ], 60 | imports: [ 61 | RouterModule.forRoot(appRoutes), 62 | BrowserModule, 63 | FormsModule, 64 | ReactiveFormsModule, 65 | HttpClientModule, 66 | BrowserAnimationsModule, 67 | MatInputModule, 68 | MatTableModule, 69 | MatPaginatorModule, 70 | MatSortModule, 71 | MatProgressSpinnerModule, 72 | MatIconModule, 73 | MatButtonModule, 74 | MatCardModule, 75 | MatFormFieldModule 76 | ], 77 | providers: [], 78 | bootstrap: [AppComponent] 79 | }) 80 | export class AppModule { } 81 | -------------------------------------------------------------------------------- /src/app/book-create/book-create.component.css: -------------------------------------------------------------------------------- 1 | .example-form { 2 | min-width: 150px; 3 | max-width: 500px; 4 | width: 100%; 5 | } 6 | 7 | .example-full-width { 8 | width: 100%; 9 | } 10 | 11 | .example-full-width:nth-last-child() { 12 | margin-bottom: 10px; 13 | } 14 | 15 | .button-row { 16 | margin: 10px 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/app/book-create/book-create.component.html: -------------------------------------------------------------------------------- 1 |
2 | list 3 |
4 |
5 | 6 | 8 | 9 | Please enter ISBN 10 | 11 | 12 | 13 | 15 | 16 | Please enter Book Title 17 | 18 | 19 | 20 | 22 | 23 | Please enter Book Author 24 | 25 | 26 | 27 | 29 | 30 | Please enter Book Description 31 | 32 | 33 | 34 | 36 | 37 | Please enter Publisher 38 | 39 | 40 | 41 | 43 | 44 | Please enter Published Year 45 | 46 | 47 |
48 | 49 |
50 |
51 | -------------------------------------------------------------------------------- /src/app/book-create/book-create.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BookCreateComponent } from './book-create.component'; 4 | 5 | describe('BookCreateComponent', () => { 6 | let component: BookCreateComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ BookCreateComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BookCreateComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/book-create/book-create.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { ApiService } from '../api.service'; 4 | import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 5 | 6 | @Component({ 7 | selector: 'app-book-create', 8 | templateUrl: './book-create.component.html', 9 | styleUrls: ['./book-create.component.css'] 10 | }) 11 | export class BookCreateComponent implements OnInit { 12 | 13 | bookForm: FormGroup; 14 | isbn:string=''; 15 | title:string=''; 16 | description:string=''; 17 | author:string=''; 18 | publisher:string=''; 19 | published_year:string=''; 20 | 21 | constructor(private router: Router, private api: ApiService, private formBuilder: FormBuilder) { } 22 | 23 | ngOnInit() { 24 | this.bookForm = this.formBuilder.group({ 25 | 'isbn' : [null, Validators.required], 26 | 'title' : [null, Validators.required], 27 | 'description' : [null, Validators.required], 28 | 'author' : [null, Validators.required], 29 | 'publisher' : [null, Validators.required], 30 | 'published_year' : [null, Validators.required] 31 | }); 32 | } 33 | 34 | onFormSubmit(form:NgForm) { 35 | this.api.postBook(form) 36 | .subscribe(res => { 37 | let id = res['_id']; 38 | this.router.navigate(['/book-details', id]); 39 | }, (err) => { 40 | console.log(err); 41 | }); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/app/book-detail/book-detail.component.css: -------------------------------------------------------------------------------- 1 | .example-card { 2 | max-width: 500px; 3 | } 4 | 5 | .button-row { 6 | margin: 10px 0; 7 | } 8 | -------------------------------------------------------------------------------- /src/app/book-detail/book-detail.component.html: -------------------------------------------------------------------------------- 1 |
2 | list 3 |
4 | 5 | 6 |

{{book.title}}

7 | {{book.description}} 8 |
9 | 10 |
11 |
ISBN:
12 |
{{book.isbn}}
13 |
Author:
14 |
{{book.author}}
15 |
Publisher:
16 |
{{book.publisher}}
17 |
Publish Year:
18 |
{{book.published_year}}
19 |
Update Date:
20 |
{{book.updated_date | date}}
21 |
22 |
23 | 24 | edit 25 | delete 26 | 27 |
28 | -------------------------------------------------------------------------------- /src/app/book-detail/book-detail.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BookDetailComponent } from './book-detail.component'; 4 | 5 | describe('BookDetailComponent', () => { 6 | let component: BookDetailComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ BookDetailComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BookDetailComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/book-detail/book-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | import { ApiService } from '../api.service'; 4 | 5 | @Component({ 6 | selector: 'app-book-detail', 7 | templateUrl: './book-detail.component.html', 8 | styleUrls: ['./book-detail.component.css'] 9 | }) 10 | export class BookDetailComponent implements OnInit { 11 | 12 | book = {}; 13 | 14 | constructor(private route: ActivatedRoute, private api: ApiService, private router: Router) { } 15 | 16 | ngOnInit() { 17 | this.getBookDetails(this.route.snapshot.params['id']); 18 | } 19 | 20 | getBookDetails(id) { 21 | this.api.getBook(id) 22 | .subscribe(data => { 23 | console.log(data); 24 | this.book = data; 25 | }); 26 | } 27 | 28 | deleteBook(id) { 29 | this.api.deleteBook(id) 30 | .subscribe(res => { 31 | this.router.navigate(['/books']); 32 | }, (err) => { 33 | console.log(err); 34 | } 35 | ); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/app/book-edit/book-edit.component.css: -------------------------------------------------------------------------------- 1 | .example-form { 2 | min-width: 150px; 3 | max-width: 500px; 4 | width: 100%; 5 | } 6 | 7 | .example-full-width { 8 | width: 100%; 9 | } 10 | 11 | .example-full-width:nth-last-child() { 12 | margin-bottom: 10px; 13 | } 14 | 15 | .button-row { 16 | margin: 10px 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/app/book-edit/book-edit.component.html: -------------------------------------------------------------------------------- 1 |
2 | show 3 |
4 |
5 | 6 | 8 | 9 | Please enter ISBN 10 | 11 | 12 | 13 | 15 | 16 | Please enter Book Title 17 | 18 | 19 | 20 | 22 | 23 | Please enter Book Author 24 | 25 | 26 | 27 | 29 | 30 | Please enter Book Description 31 | 32 | 33 | 34 | 36 | 37 | Please enter Publisher 38 | 39 | 40 | 41 | 43 | 44 | Please enter Published Year 45 | 46 | 47 |
48 | 49 |
50 |
51 | -------------------------------------------------------------------------------- /src/app/book-edit/book-edit.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BookEditComponent } from './book-edit.component'; 4 | 5 | describe('BookEditComponent', () => { 6 | let component: BookEditComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ BookEditComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BookEditComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/book-edit/book-edit.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router, ActivatedRoute } from '@angular/router'; 3 | import { ApiService } from '../api.service'; 4 | import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 5 | 6 | @Component({ 7 | selector: 'app-book-edit', 8 | templateUrl: './book-edit.component.html', 9 | styleUrls: ['./book-edit.component.css'] 10 | }) 11 | export class BookEditComponent implements OnInit { 12 | 13 | bookForm: FormGroup; 14 | id:string = ''; 15 | isbn:string = ''; 16 | title:string = ''; 17 | description:string = ''; 18 | author:string = ''; 19 | publisher:string = ''; 20 | published_year:string = ''; 21 | 22 | constructor(private router: Router, private route: ActivatedRoute, private api: ApiService, private formBuilder: FormBuilder) { } 23 | 24 | ngOnInit() { 25 | this.getBook(this.route.snapshot.params['id']); 26 | this.bookForm = this.formBuilder.group({ 27 | 'isbn' : [null, Validators.required], 28 | 'title' : [null, Validators.required], 29 | 'description' : [null, Validators.required], 30 | 'author' : [null, Validators.required], 31 | 'publisher' : [null, Validators.required], 32 | 'published_year' : [null, Validators.required] 33 | }); 34 | } 35 | 36 | getBook(id) { 37 | this.api.getBook(id).subscribe(data => { 38 | this.id = data._id; 39 | this.bookForm.setValue({ 40 | isbn: data.isbn, 41 | title: data.title, 42 | description: data.description, 43 | author: data.author, 44 | publisher: data.publisher, 45 | published_year: data.published_year 46 | }); 47 | }); 48 | } 49 | 50 | onFormSubmit(form:NgForm) { 51 | this.api.updateBook(this.id, form) 52 | .subscribe(res => { 53 | let id = res['_id']; 54 | this.router.navigate(['/book-details', id]); 55 | }, (err) => { 56 | console.log(err); 57 | } 58 | ); 59 | } 60 | 61 | bookDetails() { 62 | this.router.navigate(['/book-details', this.id]); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/app/book/book.component.css: -------------------------------------------------------------------------------- 1 | .example-container { 2 | display: flex; 3 | flex-direction: column; 4 | max-height: 500px; 5 | min-width: 300px; 6 | overflow: auto; 7 | } 8 | 9 | .isbn-col { 10 | flex: 0 0 100px !important; 11 | white-space: unset !important; 12 | } 13 | 14 | .button-row { 15 | margin: 10px 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/app/book/book.component.html: -------------------------------------------------------------------------------- 1 |
2 | add 3 |
4 |
5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
ISBN {{element.isbn}} Title {{element.title}} Author {{element.author}}
31 |
32 | -------------------------------------------------------------------------------- /src/app/book/book.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BookComponent } from './book.component'; 4 | 5 | describe('BookComponent', () => { 6 | let component: BookComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ BookComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BookComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/book/book.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ApiService } from '../api.service'; 3 | import { DataSource } from '@angular/cdk/collections'; 4 | import { Observable } from 'rxjs'; 5 | 6 | @Component({ 7 | selector: 'app-book', 8 | templateUrl: './book.component.html', 9 | styleUrls: ['./book.component.css'] 10 | }) 11 | export class BookComponent implements OnInit { 12 | 13 | books: any; 14 | displayedColumns = ['isbn', 'title', 'author']; 15 | dataSource = new BookDataSource(this.api); 16 | 17 | constructor(private api: ApiService) { } 18 | 19 | ngOnInit() { 20 | this.api.getBooks() 21 | .subscribe(res => { 22 | console.log(res); 23 | this.books = res; 24 | }, err => { 25 | console.log(err); 26 | }); 27 | } 28 | } 29 | 30 | export class BookDataSource extends DataSource { 31 | constructor(private api: ApiService) { 32 | super() 33 | } 34 | 35 | connect() { 36 | return this.api.getBooks(); 37 | } 38 | 39 | disconnect() { 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular6-crud-example/0efdf5cd350f7db35da3d5b21f1f5e7bed1abcfc/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed 5 | > 0.5% 6 | last 2 versions 7 | Firefox ESR 8 | not dead 9 | # IE 9-11 -------------------------------------------------------------------------------- /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 | * In development mode, to ignore zone related error stack frames such as 11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can 12 | * import the following file, but please comment it out in production mode 13 | * because it will have performance impact when throw error 14 | */ 15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 16 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular6-crud-example/0efdf5cd350f7db35da3d5b21f1f5e7bed1abcfc/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | MeanAngular6 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/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'), 20 | reports: ['html', 'lcovonly'], 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 | }); 31 | }; -------------------------------------------------------------------------------- /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.log(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/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Web Animations `@angular/platform-browser/animations` 51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 53 | **/ 54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 55 | 56 | /** 57 | * By default, zone.js will patch all possible macroTask and DomEvents 58 | * user can disable parts of macroTask/DomEvents patch by setting following flags 59 | */ 60 | 61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 64 | 65 | /* 66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 68 | */ 69 | // (window as any).__Zone_enable_cross_context_check = true; 70 | 71 | /*************************************************************************************************** 72 | * Zone JS is required by default for Angular itself. 73 | */ 74 | import 'zone.js/dist/zone'; // Included with Angular CLI. 75 | 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | body { margin: 0 5%; } 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "types": [] 7 | }, 8 | "exclude": [ 9 | "src/test.ts", 10 | "**/*.spec.ts" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "types": [ 7 | "jasmine", 8 | "node" 9 | ] 10 | }, 11 | "files": [ 12 | "test.ts", 13 | "polyfills.ts" 14 | ], 15 | "include": [ 16 | "**/*.spec.ts", 17 | "**/*.d.ts" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "moduleResolution": "node", 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "node_modules/@types" 14 | ], 15 | "lib": [ 16 | "es2017", 17 | "dom" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 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-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-shadowed-variable": true, 69 | "no-string-literal": false, 70 | "no-string-throw": true, 71 | "no-switch-case-fall-through": true, 72 | "no-trailing-whitespace": true, 73 | "no-unnecessary-initializer": true, 74 | "no-unused-expression": true, 75 | "no-use-before-declare": true, 76 | "no-var-keyword": true, 77 | "object-literal-sort-keys": false, 78 | "one-line": [ 79 | true, 80 | "check-open-brace", 81 | "check-catch", 82 | "check-else", 83 | "check-whitespace" 84 | ], 85 | "prefer-const": true, 86 | "quotemark": [ 87 | true, 88 | "single" 89 | ], 90 | "radix": true, 91 | "semicolon": [ 92 | true, 93 | "always" 94 | ], 95 | "triple-equals": [ 96 | true, 97 | "allow-null-check" 98 | ], 99 | "typedef-whitespace": [ 100 | true, 101 | { 102 | "call-signature": "nospace", 103 | "index-signature": "nospace", 104 | "parameter": "nospace", 105 | "property-declaration": "nospace", 106 | "variable-declaration": "nospace" 107 | } 108 | ], 109 | "unified-signatures": true, 110 | "variable-name": false, 111 | "whitespace": [ 112 | true, 113 | "check-branch", 114 | "check-decl", 115 | "check-operator", 116 | "check-separator", 117 | "check-type" 118 | ], 119 | "no-output-on-prefix": true, 120 | "use-input-property-decorator": true, 121 | "use-output-property-decorator": true, 122 | "use-host-property-decorator": true, 123 | "no-input-rename": true, 124 | "no-output-rename": true, 125 | "use-life-cycle-interface": true, 126 | "use-pipe-transform-interface": true, 127 | "component-class-suffix": true, 128 | "directive-class-suffix": true 129 | } 130 | } 131 | --------------------------------------------------------------------------------