├── .gitignore ├── LICENSE ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.e2e.json ├── ionic.config.json ├── package.json ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── auth │ │ ├── login │ │ │ ├── login.module.ts │ │ │ ├── login.page.html │ │ │ ├── login.page.scss │ │ │ ├── login.page.spec.ts │ │ │ └── login.page.ts │ │ ├── register │ │ │ ├── register.module.ts │ │ │ ├── register.page.html │ │ │ ├── register.page.scss │ │ │ ├── register.page.spec.ts │ │ │ └── register.page.ts │ │ └── reset-password │ │ │ ├── reset-password.module.ts │ │ │ ├── reset-password.page.html │ │ │ ├── reset-password.page.scss │ │ │ ├── reset-password.page.spec.ts │ │ │ └── reset-password.page.ts │ ├── book │ │ ├── book.module.ts │ │ ├── book.page.html │ │ ├── book.page.scss │ │ ├── book.page.spec.ts │ │ ├── book.page.ts │ │ └── book.ts │ ├── home │ │ ├── home.module.ts │ │ ├── home.page.html │ │ ├── home.page.scss │ │ ├── home.page.spec.ts │ │ └── home.page.ts │ ├── inteceptors │ │ └── token.interceptor.ts │ └── services │ │ ├── auth.service.spec.ts │ │ ├── auth.service.ts │ │ ├── book.service.spec.ts │ │ └── book.service.ts ├── assets │ ├── icon │ │ └── favicon.png │ └── shapes.svg ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── global.scss ├── index.html ├── karma.conf.js ├── main.ts ├── polyfills.ts ├── test.ts ├── theme │ └── variables.scss ├── tsconfig.app.json └── tsconfig.spec.json ├── tsconfig.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Specifies intentionally untracked files to ignore when using Git 2 | # http://git-scm.com/docs/gitignore 3 | 4 | *~ 5 | *.sw[mnpcod] 6 | *.log 7 | *.tmp 8 | *.tmp.* 9 | log.txt 10 | *.sublime-project 11 | *.sublime-workspace 12 | .vscode/ 13 | npm-debug.log* 14 | 15 | .idea/ 16 | .ionic/ 17 | .sourcemaps/ 18 | .sass-cache/ 19 | .tmp/ 20 | .versions/ 21 | coverage/ 22 | www/ 23 | node_modules/ 24 | tmp/ 25 | temp/ 26 | platforms/ 27 | plugins/ 28 | plugins/android.json 29 | plugins/ios.json 30 | $RECYCLE.BIN/ 31 | 32 | .DS_Store 33 | Thumbs.db 34 | UserInterfaceState.xcuserstate 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 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 | # Ionic 4 and Angular 7 Tutorial: HTTP Interceptor Example 2 | 3 | This source code is part of [Ionic 4 and Angular 7 Tutorial: HTTP Interceptor Example](https://www.djamware.com/post/5c42ca7580aca754f7a9d1e8/ionic-4-and-angular-7-tutorial-http-interceptor-example) 4 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json", 3 | "version": 1, 4 | "defaultProject": "app", 5 | "newProjectRoot": "projects", 6 | "projects": { 7 | "app": { 8 | "root": "", 9 | "sourceRoot": "src", 10 | "projectType": "application", 11 | "prefix": "app", 12 | "schematics": {}, 13 | "architect": { 14 | "build": { 15 | "builder": "@angular-devkit/build-angular:browser", 16 | "options": { 17 | "outputPath": "www", 18 | "index": "src/index.html", 19 | "main": "src/main.ts", 20 | "polyfills": "src/polyfills.ts", 21 | "tsConfig": "src/tsconfig.app.json", 22 | "assets": [ 23 | { 24 | "glob": "**/*", 25 | "input": "src/assets", 26 | "output": "assets" 27 | }, 28 | { 29 | "glob": "**/*.svg", 30 | "input": "node_modules/ionicons/dist/ionicons/svg", 31 | "output": "./svg" 32 | } 33 | ], 34 | "styles": [ 35 | { 36 | "input": "src/theme/variables.scss" 37 | }, 38 | { 39 | "input": "src/global.scss" 40 | } 41 | ], 42 | "scripts": [] 43 | }, 44 | "configurations": { 45 | "production": { 46 | "fileReplacements": [ 47 | { 48 | "replace": "src/environments/environment.ts", 49 | "with": "src/environments/environment.prod.ts" 50 | } 51 | ], 52 | "optimization": true, 53 | "outputHashing": "all", 54 | "sourceMap": false, 55 | "extractCss": true, 56 | "namedChunks": false, 57 | "aot": true, 58 | "extractLicenses": true, 59 | "vendorChunk": false, 60 | "buildOptimizer": true, 61 | "budgets": [ 62 | { 63 | "type": "initial", 64 | "maximumWarning": "2mb", 65 | "maximumError": "5mb" 66 | } 67 | ] 68 | }, 69 | "ci": { 70 | "progress": false 71 | } 72 | } 73 | }, 74 | "serve": { 75 | "builder": "@angular-devkit/build-angular:dev-server", 76 | "options": { 77 | "browserTarget": "app:build" 78 | }, 79 | "configurations": { 80 | "production": { 81 | "browserTarget": "app:build:production" 82 | }, 83 | "ci": { 84 | "progress": false 85 | } 86 | } 87 | }, 88 | "extract-i18n": { 89 | "builder": "@angular-devkit/build-angular:extract-i18n", 90 | "options": { 91 | "browserTarget": "app:build" 92 | } 93 | }, 94 | "test": { 95 | "builder": "@angular-devkit/build-angular:karma", 96 | "options": { 97 | "main": "src/test.ts", 98 | "polyfills": "src/polyfills.ts", 99 | "tsConfig": "src/tsconfig.spec.json", 100 | "karmaConfig": "src/karma.conf.js", 101 | "styles": [], 102 | "scripts": [], 103 | "assets": [ 104 | { 105 | "glob": "favicon.ico", 106 | "input": "src/", 107 | "output": "/" 108 | }, 109 | { 110 | "glob": "**/*", 111 | "input": "src/assets", 112 | "output": "/assets" 113 | } 114 | ] 115 | }, 116 | "configurations": { 117 | "ci": { 118 | "progress": false, 119 | "watch": false 120 | } 121 | } 122 | }, 123 | "lint": { 124 | "builder": "@angular-devkit/build-angular:tslint", 125 | "options": { 126 | "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"], 127 | "exclude": ["**/node_modules/**"] 128 | } 129 | }, 130 | "ionic-cordova-build": { 131 | "builder": "@ionic/angular-toolkit:cordova-build", 132 | "options": { 133 | "browserTarget": "app:build" 134 | }, 135 | "configurations": { 136 | "production": { 137 | "browserTarget": "app:build:production" 138 | } 139 | } 140 | }, 141 | "ionic-cordova-serve": { 142 | "builder": "@ionic/angular-toolkit:cordova-serve", 143 | "options": { 144 | "cordovaBuildTarget": "app:ionic-cordova-build", 145 | "devServerTarget": "app:serve" 146 | }, 147 | "configurations": { 148 | "production": { 149 | "cordovaBuildTarget": "app:ionic-cordova-build:production", 150 | "devServerTarget": "app:serve:production" 151 | } 152 | } 153 | } 154 | } 155 | }, 156 | "app-e2e": { 157 | "root": "e2e/", 158 | "projectType": "application", 159 | "architect": { 160 | "e2e": { 161 | "builder": "@angular-devkit/build-angular:protractor", 162 | "options": { 163 | "protractorConfig": "e2e/protractor.conf.js", 164 | "devServerTarget": "app:serve" 165 | }, 166 | "configurations": { 167 | "ci": { 168 | "devServerTarget": "app:serve:ci" 169 | } 170 | } 171 | }, 172 | "lint": { 173 | "builder": "@angular-devkit/build-angular:tslint", 174 | "options": { 175 | "tsConfig": "e2e/tsconfig.e2e.json", 176 | "exclude": ["**/node_modules/**"] 177 | } 178 | } 179 | } 180 | } 181 | }, 182 | "cli": { 183 | "defaultCollection": "@ionic/angular-toolkit" 184 | }, 185 | "schematics": { 186 | "@ionic/angular-toolkit:component": { 187 | "styleext": "scss" 188 | }, 189 | "@ionic/angular-toolkit:page": { 190 | "styleext": "scss" 191 | } 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /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: 'e2e/tsconfig.e2e.json' 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('new App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should be blank', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toContain('The world is your oyster.'); 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.deepCss('app-root ion-content')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ionic.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic4-angular7-interceptor", 3 | "integrations": {}, 4 | "type": "angular" 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic4-angular7-interceptor", 3 | "version": "0.0.1", 4 | "author": "Ionic Framework", 5 | "homepage": "http://ionicframework.com/", 6 | "scripts": { 7 | "ng": "ng", 8 | "start": "ng serve", 9 | "build": "ng build", 10 | "test": "ng test", 11 | "lint": "ng lint", 12 | "e2e": "ng e2e" 13 | }, 14 | "private": true, 15 | "dependencies": { 16 | "@angular/common": "~7.1.4", 17 | "@angular/core": "~7.1.4", 18 | "@angular/forms": "~7.1.4", 19 | "@angular/http": "~7.1.4", 20 | "@angular/platform-browser": "~7.1.4", 21 | "@angular/platform-browser-dynamic": "~7.1.4", 22 | "@angular/router": "~7.1.4", 23 | "@ionic-native/core": "5.0.0-beta.21", 24 | "@ionic-native/splash-screen": "5.0.0-beta.21", 25 | "@ionic-native/status-bar": "5.0.0-beta.21", 26 | "@ionic/angular": "4.0.0-rc.1", 27 | "@ionic/storage": "^2.2.0", 28 | "core-js": "^2.5.4", 29 | "rxjs": "~6.3.3", 30 | "zone.js": "~0.8.26" 31 | }, 32 | "devDependencies": { 33 | "@angular-devkit/architect": "~0.11.4", 34 | "@angular-devkit/build-angular": "^0.12.1", 35 | "@angular-devkit/core": "~7.1.4", 36 | "@angular-devkit/schematics": "~7.1.4", 37 | "@angular/cli": "~7.1.4", 38 | "@angular/compiler": "~7.1.4", 39 | "@angular/compiler-cli": "~7.1.4", 40 | "@angular/language-service": "~7.1.4", 41 | "@ionic/angular-toolkit": "~1.2.0", 42 | "@ionic/lab": "^1.0.18", 43 | "@types/jasmine": "~2.8.8", 44 | "@types/jasminewd2": "~2.0.3", 45 | "@types/node": "~10.12.0", 46 | "codelyzer": "~4.5.0", 47 | "jasmine-core": "~2.99.1", 48 | "jasmine-spec-reporter": "~4.2.1", 49 | "karma": "~3.1.4", 50 | "karma-chrome-launcher": "~2.2.0", 51 | "karma-coverage-istanbul-reporter": "~2.0.1", 52 | "karma-jasmine": "~1.1.2", 53 | "karma-jasmine-html-reporter": "^0.2.2", 54 | "protractor": "~5.4.0", 55 | "ts-node": "~7.0.0", 56 | "tslint": "~5.12.0", 57 | "typescript": "~3.1.6" 58 | }, 59 | "description": "An Ionic project" 60 | } 61 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | const routes: Routes = [ 5 | { path: '', redirectTo: 'book', pathMatch: 'full' }, 6 | { path: 'home', loadChildren: './home/home.module#HomePageModule' }, 7 | { path: 'book', loadChildren: './book/book.module#BookPageModule' }, 8 | { path: 'login', loadChildren: './auth/login/login.module#LoginPageModule' }, 9 | { path: 'register', loadChildren: './auth/register/register.module#RegisterPageModule' }, 10 | { path: 'reset-password', loadChildren: './auth/reset-password/reset-password.module#ResetPasswordPageModule' }, 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [RouterModule.forRoot(routes)], 15 | exports: [RouterModule] 16 | }) 17 | export class AppRoutingModule { } 18 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 2 | import { TestBed, async } from '@angular/core/testing'; 3 | 4 | import { Platform } from '@ionic/angular'; 5 | import { SplashScreen } from '@ionic-native/splash-screen/ngx'; 6 | import { StatusBar } from '@ionic-native/status-bar/ngx'; 7 | 8 | import { AppComponent } from './app.component'; 9 | 10 | describe('AppComponent', () => { 11 | 12 | let statusBarSpy, splashScreenSpy, platformReadySpy, platformSpy; 13 | 14 | beforeEach(async(() => { 15 | statusBarSpy = jasmine.createSpyObj('StatusBar', ['styleDefault']); 16 | splashScreenSpy = jasmine.createSpyObj('SplashScreen', ['hide']); 17 | platformReadySpy = Promise.resolve(); 18 | platformSpy = jasmine.createSpyObj('Platform', { ready: platformReadySpy }); 19 | 20 | TestBed.configureTestingModule({ 21 | declarations: [AppComponent], 22 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 23 | providers: [ 24 | { provide: StatusBar, useValue: statusBarSpy }, 25 | { provide: SplashScreen, useValue: splashScreenSpy }, 26 | { provide: Platform, useValue: platformSpy }, 27 | ], 28 | }).compileComponents(); 29 | })); 30 | 31 | it('should create the app', () => { 32 | const fixture = TestBed.createComponent(AppComponent); 33 | const app = fixture.debugElement.componentInstance; 34 | expect(app).toBeTruthy(); 35 | }); 36 | 37 | it('should initialize the app', async () => { 38 | TestBed.createComponent(AppComponent); 39 | expect(platformSpy.ready).toHaveBeenCalled(); 40 | await platformReadySpy; 41 | expect(statusBarSpy.styleDefault).toHaveBeenCalled(); 42 | expect(splashScreenSpy.hide).toHaveBeenCalled(); 43 | }); 44 | 45 | // TODO: add more tests! 46 | 47 | }); 48 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | import { Platform } from '@ionic/angular'; 4 | import { SplashScreen } from '@ionic-native/splash-screen/ngx'; 5 | import { StatusBar } from '@ionic-native/status-bar/ngx'; 6 | 7 | @Component({ 8 | selector: 'app-root', 9 | templateUrl: 'app.component.html' 10 | }) 11 | export class AppComponent { 12 | constructor( 13 | private platform: Platform, 14 | private splashScreen: SplashScreen, 15 | private statusBar: StatusBar 16 | ) { 17 | this.initializeApp(); 18 | } 19 | 20 | initializeApp() { 21 | this.platform.ready().then(() => { 22 | this.statusBar.styleDefault(); 23 | this.splashScreen.hide(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { RouteReuseStrategy } from '@angular/router'; 4 | 5 | import { IonicModule, IonicRouteStrategy } from '@ionic/angular'; 6 | import { SplashScreen } from '@ionic-native/splash-screen/ngx'; 7 | import { StatusBar } from '@ionic-native/status-bar/ngx'; 8 | 9 | import { AppComponent } from './app.component'; 10 | import { AppRoutingModule } from './app-routing.module'; 11 | 12 | import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http'; 13 | import { TokenInterceptor } from './inteceptors/token.interceptor'; 14 | import { IonicStorageModule } from '@ionic/storage'; 15 | 16 | @NgModule({ 17 | declarations: [AppComponent], 18 | entryComponents: [], 19 | imports: [ 20 | BrowserModule, 21 | IonicModule.forRoot(), 22 | AppRoutingModule, 23 | HttpClientModule, 24 | IonicStorageModule.forRoot({ 25 | name: 'ionic4tutorial', 26 | storeName: 'ionic4tutorialData', 27 | }) 28 | ], 29 | providers: [ 30 | StatusBar, 31 | SplashScreen, 32 | { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, 33 | { 34 | provide: HTTP_INTERCEPTORS, 35 | useClass: TokenInterceptor, 36 | multi: true 37 | } 38 | ], 39 | bootstrap: [AppComponent] 40 | }) 41 | export class AppModule {} 42 | -------------------------------------------------------------------------------- /src/app/auth/login/login.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 4 | import { Routes, RouterModule } from '@angular/router'; 5 | 6 | import { IonicModule } from '@ionic/angular'; 7 | 8 | import { LoginPage } from './login.page'; 9 | 10 | const routes: Routes = [ 11 | { 12 | path: '', 13 | component: LoginPage 14 | } 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [ 19 | CommonModule, 20 | FormsModule, 21 | ReactiveFormsModule, 22 | IonicModule, 23 | RouterModule.forChild(routes) 24 | ], 25 | declarations: [LoginPage] 26 | }) 27 | export class LoginPageModule {} 28 | -------------------------------------------------------------------------------- /src/app/auth/login/login.page.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | Please, Sign In 6 | 7 | 8 | 9 | Username 10 | 11 | 12 | 13 | Password 14 | 15 | 16 | 17 | Login 18 | 19 | 20 | Register 21 | 22 | 23 | 24 |
25 |
26 | -------------------------------------------------------------------------------- /src/app/auth/login/login.page.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/ionic4-angular7-httpinterceptor-example/090ed857bbf28e419cdc85b5a681b2acc394ad0b/src/app/auth/login/login.page.scss -------------------------------------------------------------------------------- /src/app/auth/login/login.page.spec.ts: -------------------------------------------------------------------------------- 1 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | 4 | import { LoginPage } from './login.page'; 5 | 6 | describe('LoginPage', () => { 7 | let component: LoginPage; 8 | let fixture: ComponentFixture; 9 | 10 | beforeEach(async(() => { 11 | TestBed.configureTestingModule({ 12 | declarations: [ LoginPage ], 13 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 14 | }) 15 | .compileComponents(); 16 | })); 17 | 18 | beforeEach(() => { 19 | fixture = TestBed.createComponent(LoginPage); 20 | component = fixture.componentInstance; 21 | fixture.detectChanges(); 22 | }); 23 | 24 | it('should create', () => { 25 | expect(component).toBeTruthy(); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /src/app/auth/login/login.page.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 3 | import { AuthService } from '../../services/auth.service'; 4 | import { Router } from '@angular/router'; 5 | import { ToastController } from '@ionic/angular'; 6 | 7 | @Component({ 8 | selector: 'app-login', 9 | templateUrl: './login.page.html', 10 | styleUrls: ['./login.page.scss'], 11 | }) 12 | export class LoginPage implements OnInit { 13 | 14 | loginForm: FormGroup; 15 | 16 | constructor(private formBuilder: FormBuilder, 17 | private router: Router, 18 | private authService: AuthService, 19 | public toastController: ToastController) { } 20 | 21 | ngOnInit() { 22 | this.loginForm = this.formBuilder.group({ 23 | 'username' : [null, Validators.required], 24 | 'password' : [null, Validators.required] 25 | }); 26 | } 27 | 28 | onFormSubmit(form: NgForm) { 29 | this.authService.login(form) 30 | .subscribe(res => { 31 | if (res.token) { 32 | localStorage.setItem('token', res.token); 33 | this.router.navigate(['book']); 34 | } 35 | }, (err) => { 36 | console.log(err); 37 | }); 38 | } 39 | 40 | register() { 41 | this.router.navigate(['register']); 42 | } 43 | 44 | async presentToast(msg) { 45 | const toast = await this.toastController.create({ 46 | message: msg, 47 | duration: 2000, 48 | position: 'top' 49 | }); 50 | toast.present(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/app/auth/register/register.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 4 | import { Routes, RouterModule } from '@angular/router'; 5 | 6 | import { IonicModule } from '@ionic/angular'; 7 | 8 | import { RegisterPage } from './register.page'; 9 | 10 | const routes: Routes = [ 11 | { 12 | path: '', 13 | component: RegisterPage 14 | } 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [ 19 | CommonModule, 20 | FormsModule, 21 | ReactiveFormsModule, 22 | IonicModule, 23 | RouterModule.forChild(routes) 24 | ], 25 | declarations: [RegisterPage] 26 | }) 27 | export class RegisterPageModule {} 28 | -------------------------------------------------------------------------------- /src/app/auth/register/register.page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Register 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | Register here 15 | 16 | 17 | 18 | Username 19 | 20 | 21 | 22 | Password 23 | 24 | 25 | 26 | Register 27 | 28 | 29 | 30 |
31 |
32 | -------------------------------------------------------------------------------- /src/app/auth/register/register.page.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/ionic4-angular7-httpinterceptor-example/090ed857bbf28e419cdc85b5a681b2acc394ad0b/src/app/auth/register/register.page.scss -------------------------------------------------------------------------------- /src/app/auth/register/register.page.spec.ts: -------------------------------------------------------------------------------- 1 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | 4 | import { RegisterPage } from './register.page'; 5 | 6 | describe('RegisterPage', () => { 7 | let component: RegisterPage; 8 | let fixture: ComponentFixture; 9 | 10 | beforeEach(async(() => { 11 | TestBed.configureTestingModule({ 12 | declarations: [ RegisterPage ], 13 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 14 | }) 15 | .compileComponents(); 16 | })); 17 | 18 | beforeEach(() => { 19 | fixture = TestBed.createComponent(RegisterPage); 20 | component = fixture.componentInstance; 21 | fixture.detectChanges(); 22 | }); 23 | 24 | it('should create', () => { 25 | expect(component).toBeTruthy(); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /src/app/auth/register/register.page.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 3 | import { AuthService } from '../../services/auth.service'; 4 | import { Router } from '@angular/router'; 5 | import { ToastController, AlertController } from '@ionic/angular'; 6 | 7 | @Component({ 8 | selector: 'app-register', 9 | templateUrl: './register.page.html', 10 | styleUrls: ['./register.page.scss'], 11 | }) 12 | export class RegisterPage implements OnInit { 13 | 14 | registerForm: FormGroup; 15 | 16 | constructor(private formBuilder: FormBuilder, 17 | private router: Router, 18 | private authService: AuthService, 19 | public toastController: ToastController, 20 | public alertController: AlertController) { } 21 | 22 | ngOnInit() { 23 | this.registerForm = this.formBuilder.group({ 24 | 'username' : [null, Validators.required], 25 | 'password' : [null, Validators.required] 26 | }); 27 | } 28 | 29 | onFormSubmit(form: NgForm) { 30 | this.authService.register(form) 31 | .subscribe(_ => { 32 | this.presentAlert('Register Successfully', 'Please login with your new username and password'); 33 | }, (err) => { 34 | console.log(err); 35 | }); 36 | } 37 | 38 | async presentToast(msg) { 39 | const toast = await this.toastController.create({ 40 | message: msg, 41 | duration: 2000, 42 | position: 'top' 43 | }); 44 | toast.present(); 45 | } 46 | 47 | async presentAlert(header, message) { 48 | const alert = await this.alertController.create({ 49 | header: header, 50 | message: message, 51 | buttons: [{ 52 | text: 'OK', 53 | handler: () => { 54 | this.router.navigate(['login']); 55 | } 56 | }] 57 | }); 58 | 59 | await alert.present(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/app/auth/reset-password/reset-password.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { Routes, RouterModule } from '@angular/router'; 5 | 6 | import { IonicModule } from '@ionic/angular'; 7 | 8 | import { ResetPasswordPage } from './reset-password.page'; 9 | 10 | const routes: Routes = [ 11 | { 12 | path: '', 13 | component: ResetPasswordPage 14 | } 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [ 19 | CommonModule, 20 | FormsModule, 21 | IonicModule, 22 | RouterModule.forChild(routes) 23 | ], 24 | declarations: [ResetPasswordPage] 25 | }) 26 | export class ResetPasswordPageModule {} 27 | -------------------------------------------------------------------------------- /src/app/auth/reset-password/reset-password.page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | reset-password 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/app/auth/reset-password/reset-password.page.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/ionic4-angular7-httpinterceptor-example/090ed857bbf28e419cdc85b5a681b2acc394ad0b/src/app/auth/reset-password/reset-password.page.scss -------------------------------------------------------------------------------- /src/app/auth/reset-password/reset-password.page.spec.ts: -------------------------------------------------------------------------------- 1 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | 4 | import { ResetPasswordPage } from './reset-password.page'; 5 | 6 | describe('ResetPasswordPage', () => { 7 | let component: ResetPasswordPage; 8 | let fixture: ComponentFixture; 9 | 10 | beforeEach(async(() => { 11 | TestBed.configureTestingModule({ 12 | declarations: [ ResetPasswordPage ], 13 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 14 | }) 15 | .compileComponents(); 16 | })); 17 | 18 | beforeEach(() => { 19 | fixture = TestBed.createComponent(ResetPasswordPage); 20 | component = fixture.componentInstance; 21 | fixture.detectChanges(); 22 | }); 23 | 24 | it('should create', () => { 25 | expect(component).toBeTruthy(); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /src/app/auth/reset-password/reset-password.page.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-reset-password', 5 | templateUrl: './reset-password.page.html', 6 | styleUrls: ['./reset-password.page.scss'], 7 | }) 8 | export class ResetPasswordPage implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/book/book.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { Routes, RouterModule } from '@angular/router'; 5 | 6 | import { IonicModule } from '@ionic/angular'; 7 | 8 | import { BookPage } from './book.page'; 9 | 10 | const routes: Routes = [ 11 | { 12 | path: '', 13 | component: BookPage 14 | } 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [ 19 | CommonModule, 20 | FormsModule, 21 | IonicModule, 22 | RouterModule.forChild(routes) 23 | ], 24 | declarations: [BookPage] 25 | }) 26 | export class BookPageModule {} 27 | -------------------------------------------------------------------------------- /src/app/book/book.page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | List of Books 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | {{b.title}} 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/app/book/book.page.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/ionic4-angular7-httpinterceptor-example/090ed857bbf28e419cdc85b5a681b2acc394ad0b/src/app/book/book.page.scss -------------------------------------------------------------------------------- /src/app/book/book.page.spec.ts: -------------------------------------------------------------------------------- 1 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | 4 | import { BookPage } from './book.page'; 5 | 6 | describe('BookPage', () => { 7 | let component: BookPage; 8 | let fixture: ComponentFixture; 9 | 10 | beforeEach(async(() => { 11 | TestBed.configureTestingModule({ 12 | declarations: [ BookPage ], 13 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 14 | }) 15 | .compileComponents(); 16 | })); 17 | 18 | beforeEach(() => { 19 | fixture = TestBed.createComponent(BookPage); 20 | component = fixture.componentInstance; 21 | fixture.detectChanges(); 22 | }); 23 | 24 | it('should create', () => { 25 | expect(component).toBeTruthy(); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /src/app/book/book.page.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Book } from './book'; 3 | import { BookService } from '../services/book.service'; 4 | import { AuthService } from '../services/auth.service'; 5 | import { Router } from '@angular/router'; 6 | 7 | @Component({ 8 | selector: 'app-book', 9 | templateUrl: './book.page.html', 10 | styleUrls: ['./book.page.scss'], 11 | }) 12 | export class BookPage implements OnInit { 13 | 14 | books: Book[]; 15 | 16 | constructor(private bookService: BookService, 17 | private authService: AuthService, 18 | private router: Router) { } 19 | 20 | ngOnInit() { 21 | this.getBooks(); 22 | } 23 | 24 | getBooks(): void { 25 | this.bookService.getBooks() 26 | .subscribe(books => { 27 | console.log(books); 28 | this.books = books; 29 | }); 30 | } 31 | 32 | logout() { 33 | this.authService.logout() 34 | .subscribe(res => { 35 | console.log(res); 36 | localStorage.removeItem('token'); 37 | this.router.navigate(['login']); 38 | }); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/app/book/book.ts: -------------------------------------------------------------------------------- 1 | export class Book { 2 | _id: number; 3 | isbn: string; 4 | title: string; 5 | author: number; 6 | publisher: Date; 7 | __v: number; 8 | } 9 | -------------------------------------------------------------------------------- /src/app/home/home.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { IonicModule } from '@ionic/angular'; 4 | import { FormsModule } from '@angular/forms'; 5 | import { RouterModule } from '@angular/router'; 6 | 7 | import { HomePage } from './home.page'; 8 | 9 | @NgModule({ 10 | imports: [ 11 | CommonModule, 12 | FormsModule, 13 | IonicModule, 14 | RouterModule.forChild([ 15 | { 16 | path: '', 17 | component: HomePage 18 | } 19 | ]) 20 | ], 21 | declarations: [HomePage] 22 | }) 23 | export class HomePageModule {} 24 | -------------------------------------------------------------------------------- /src/app/home/home.page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Ionic Blank 5 | 6 | 7 | 8 | 9 | 10 | The world is your oyster. 11 |

If you get lost, the docs will be your guide.

12 |
13 | -------------------------------------------------------------------------------- /src/app/home/home.page.scss: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/home/home.page.spec.ts: -------------------------------------------------------------------------------- 1 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | 4 | import { HomePage } from './home.page'; 5 | 6 | describe('HomePage', () => { 7 | let component: HomePage; 8 | let fixture: ComponentFixture; 9 | 10 | beforeEach(async(() => { 11 | TestBed.configureTestingModule({ 12 | declarations: [ HomePage ], 13 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 14 | }) 15 | .compileComponents(); 16 | })); 17 | 18 | beforeEach(() => { 19 | fixture = TestBed.createComponent(HomePage); 20 | component = fixture.componentInstance; 21 | fixture.detectChanges(); 22 | }); 23 | 24 | it('should create', () => { 25 | expect(component).toBeTruthy(); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /src/app/home/home.page.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-home', 5 | templateUrl: 'home.page.html', 6 | styleUrls: ['home.page.scss'], 7 | }) 8 | export class HomePage { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/app/inteceptors/token.interceptor.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { 3 | HttpRequest, 4 | HttpHandler, 5 | HttpEvent, 6 | HttpInterceptor, 7 | HttpResponse, 8 | HttpErrorResponse 9 | } from '@angular/common/http'; 10 | import { Observable, throwError } from 'rxjs'; 11 | import { map, catchError } from 'rxjs/operators'; 12 | import { 13 | Router 14 | } from '@angular/router'; 15 | import { ToastController } from '@ionic/angular'; 16 | 17 | @Injectable() 18 | export class TokenInterceptor implements HttpInterceptor { 19 | 20 | constructor(private router: Router, 21 | public toastController: ToastController) {} 22 | 23 | intercept(request: HttpRequest, next: HttpHandler): Observable> { 24 | 25 | const token = localStorage.getItem('token'); 26 | 27 | if (token) { 28 | request = request.clone({ 29 | setHeaders: { 30 | 'Authorization': token 31 | } 32 | }); 33 | } 34 | 35 | if (!request.headers.has('Content-Type')) { 36 | request = request.clone({ 37 | setHeaders: { 38 | 'content-type': 'application/json' 39 | } 40 | }); 41 | } 42 | 43 | request = request.clone({ 44 | headers: request.headers.set('Accept', 'application/json') 45 | }); 46 | 47 | return next.handle(request).pipe( 48 | map((event: HttpEvent) => { 49 | if (event instanceof HttpResponse) { 50 | console.log('event--->>>', event); 51 | } 52 | return event; 53 | }), 54 | catchError((error: HttpErrorResponse) => { 55 | if (error.status === 401) { 56 | if (error.error.success === false) { 57 | this.presentToast('Login failed'); 58 | } else { 59 | this.router.navigate(['login']); 60 | } 61 | } 62 | return throwError(error); 63 | })); 64 | } 65 | 66 | async presentToast(msg) { 67 | const toast = await this.toastController.create({ 68 | message: msg, 69 | duration: 2000, 70 | position: 'top' 71 | }); 72 | toast.present(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/app/services/auth.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { AuthService } from './auth.service'; 4 | 5 | describe('AuthService', () => { 6 | beforeEach(() => TestBed.configureTestingModule({})); 7 | 8 | it('should be created', () => { 9 | const service: AuthService = TestBed.get(AuthService); 10 | expect(service).toBeTruthy(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/app/services/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Observable, of } from 'rxjs'; 4 | import { catchError, tap } from 'rxjs/operators'; 5 | 6 | @Injectable({ 7 | providedIn: 'root' 8 | }) 9 | export class AuthService { 10 | 11 | apiUrl = 'http://localhost:3000/api/'; 12 | 13 | constructor(private http: HttpClient) { } 14 | 15 | login (data): Observable { 16 | return this.http.post(this.apiUrl + 'signin', data) 17 | .pipe( 18 | tap(_ => this.log('login')), 19 | catchError(this.handleError('login', [])) 20 | ); 21 | } 22 | 23 | logout (): Observable { 24 | return this.http.get(this.apiUrl + 'signout') 25 | .pipe( 26 | tap(_ => this.log('logout')), 27 | catchError(this.handleError('logout', [])) 28 | ); 29 | } 30 | 31 | register (data): Observable { 32 | return this.http.post(this.apiUrl + 'signup', data) 33 | .pipe( 34 | tap(_ => this.log('login')), 35 | catchError(this.handleError('login', [])) 36 | ); 37 | } 38 | 39 | private handleError (operation = 'operation', result?: T) { 40 | return (error: any): Observable => { 41 | 42 | // TODO: send the error to remote logging infrastructure 43 | console.error(error); // log to console instead 44 | 45 | // TODO: better job of transforming error for user consumption 46 | this.log(`${operation} failed: ${error.message}`); 47 | 48 | // Let the app keep running by returning an empty result. 49 | return of(result as T); 50 | }; 51 | } 52 | 53 | /** Log a HeroService message with the MessageService */ 54 | private log(message: string) { 55 | console.log(message); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/app/services/book.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { BookService } from './book.service'; 4 | 5 | describe('BookService', () => { 6 | beforeEach(() => TestBed.configureTestingModule({})); 7 | 8 | it('should be created', () => { 9 | const service: BookService = TestBed.get(BookService); 10 | expect(service).toBeTruthy(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/app/services/book.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Book } from '../book/book'; 3 | import { HttpClient } from '@angular/common/http'; 4 | import { Observable, of } from 'rxjs'; 5 | import { catchError, tap } from 'rxjs/operators'; 6 | 7 | @Injectable({ 8 | providedIn: 'root' 9 | }) 10 | export class BookService { 11 | 12 | apiUrl = 'http://localhost:3000/api/'; 13 | 14 | constructor(private http: HttpClient) { } 15 | 16 | getBooks (): Observable { 17 | return this.http.get(this.apiUrl + 'book') 18 | .pipe( 19 | tap(_ => this.log('fetched books')), 20 | catchError(this.handleError('getBooks', [])) 21 | ); 22 | } 23 | 24 | private handleError (operation = 'operation', result?: T) { 25 | return (error: any): Observable => { 26 | 27 | // TODO: send the error to remote logging infrastructure 28 | console.error(error); // log to console instead 29 | 30 | // TODO: better job of transforming error for user consumption 31 | this.log(`${operation} failed: ${error.message}`); 32 | 33 | // Let the app keep running by returning an empty result. 34 | return of(result as T); 35 | }; 36 | } 37 | 38 | /** Log a HeroService message with the MessageService */ 39 | private log(message: string) { 40 | console.log(message); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/assets/icon/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/ionic4-angular7-httpinterceptor-example/090ed857bbf28e419cdc85b5a681b2acc394ad0b/src/assets/icon/favicon.png -------------------------------------------------------------------------------- /src/assets/shapes.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /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/global.scss: -------------------------------------------------------------------------------- 1 | // http://ionicframework.com/docs/theming/ 2 | @import '~@ionic/angular/css/core.css'; 3 | @import '~@ionic/angular/css/normalize.css'; 4 | @import '~@ionic/angular/css/structure.css'; 5 | @import '~@ionic/angular/css/typography.css'; 6 | 7 | @import '~@ionic/angular/css/padding.css'; 8 | @import '~@ionic/angular/css/float-elements.css'; 9 | @import '~@ionic/angular/css/text-alignment.css'; 10 | @import '~@ionic/angular/css/text-transformation.css'; 11 | @import '~@ionic/angular/css/flex-utils.css'; 12 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Ionic App 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /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 | }; 32 | -------------------------------------------------------------------------------- /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/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10, IE11, and older Chrome 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 | /** 38 | * If the application will be indexed by Google Search, the following is required. 39 | * Googlebot uses a renderer based on Chrome 41. 40 | * https://developers.google.com/search/docs/guides/rendering 41 | **/ 42 | // import 'core-js/es6/array'; 43 | 44 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 45 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 46 | 47 | /** IE10 and IE11 requires the following for the Reflect API. */ 48 | // import 'core-js/es6/reflect'; 49 | 50 | /** 51 | * Web Animations `@angular/platform-browser/animations` 52 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 53 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 54 | **/ 55 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 56 | 57 | /** 58 | * By default, zone.js will patch all possible macroTask and DomEvents 59 | * user can disable parts of macroTask/DomEvents patch by setting following flags 60 | * because those flags need to be set before `zone.js` being loaded, and webpack 61 | * will put import in the top of bundle, so user need to create a separate file 62 | * in this directory (for example: zone-flags.ts), and put the following flags 63 | * into that file, and then add the following code before importing zone.js. 64 | * import './zone-flags.ts'; 65 | * 66 | * The flags allowed in zone-flags.ts are listed here. 67 | * 68 | * The following flags will work for all browsers. 69 | * 70 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 71 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 72 | * (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 73 | * 74 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 75 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 76 | * 77 | * (window as any).__Zone_enable_cross_context_check = true; 78 | * 79 | */ 80 | 81 | /*************************************************************************************************** 82 | * Zone JS is required by default for Angular itself. 83 | */ 84 | import 'zone.js/dist/zone'; // Included with Angular CLI. 85 | 86 | 87 | /*************************************************************************************************** 88 | * APPLICATION IMPORTS 89 | */ 90 | -------------------------------------------------------------------------------- /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/theme/variables.scss: -------------------------------------------------------------------------------- 1 | // Ionic Variables and Theming. For more info, please see: 2 | // http://ionicframework.com/docs/theming/ 3 | 4 | /** Ionic CSS Variables **/ 5 | :root { 6 | /** primary **/ 7 | --ion-color-primary: #3880ff; 8 | --ion-color-primary-rgb: 56, 128, 255; 9 | --ion-color-primary-contrast: #ffffff; 10 | --ion-color-primary-contrast-rgb: 255, 255, 255; 11 | --ion-color-primary-shade: #3171e0; 12 | --ion-color-primary-tint: #4c8dff; 13 | 14 | /** secondary **/ 15 | --ion-color-secondary: #0cd1e8; 16 | --ion-color-secondary-rgb: 12, 209, 232; 17 | --ion-color-secondary-contrast: #ffffff; 18 | --ion-color-secondary-contrast-rgb: 255, 255, 255; 19 | --ion-color-secondary-shade: #0bb8cc; 20 | --ion-color-secondary-tint: #24d6ea; 21 | 22 | /** tertiary **/ 23 | --ion-color-tertiary: #7044ff; 24 | --ion-color-tertiary-rgb: 112, 68, 255; 25 | --ion-color-tertiary-contrast: #ffffff; 26 | --ion-color-tertiary-contrast-rgb: 255, 255, 255; 27 | --ion-color-tertiary-shade: #633ce0; 28 | --ion-color-tertiary-tint: #7e57ff; 29 | 30 | /** success **/ 31 | --ion-color-success: #10dc60; 32 | --ion-color-success-rgb: 16, 220, 96; 33 | --ion-color-success-contrast: #ffffff; 34 | --ion-color-success-contrast-rgb: 255, 255, 255; 35 | --ion-color-success-shade: #0ec254; 36 | --ion-color-success-tint: #28e070; 37 | 38 | /** warning **/ 39 | --ion-color-warning: #ffce00; 40 | --ion-color-warning-rgb: 255, 206, 0; 41 | --ion-color-warning-contrast: #ffffff; 42 | --ion-color-warning-contrast-rgb: 255, 255, 255; 43 | --ion-color-warning-shade: #e0b500; 44 | --ion-color-warning-tint: #ffd31a; 45 | 46 | /** danger **/ 47 | --ion-color-danger: #f04141; 48 | --ion-color-danger-rgb: 245, 61, 61; 49 | --ion-color-danger-contrast: #ffffff; 50 | --ion-color-danger-contrast-rgb: 255, 255, 255; 51 | --ion-color-danger-shade: #d33939; 52 | --ion-color-danger-tint: #f25454; 53 | 54 | /** dark **/ 55 | --ion-color-dark: #222428; 56 | --ion-color-dark-rgb: 34, 34, 34; 57 | --ion-color-dark-contrast: #ffffff; 58 | --ion-color-dark-contrast-rgb: 255, 255, 255; 59 | --ion-color-dark-shade: #1e2023; 60 | --ion-color-dark-tint: #383a3e; 61 | 62 | /** medium **/ 63 | --ion-color-medium: #989aa2; 64 | --ion-color-medium-rgb: 152, 154, 162; 65 | --ion-color-medium-contrast: #ffffff; 66 | --ion-color-medium-contrast-rgb: 255, 255, 255; 67 | --ion-color-medium-shade: #86888f; 68 | --ion-color-medium-tint: #a2a4ab; 69 | 70 | /** light **/ 71 | --ion-color-light: #f4f5f8; 72 | --ion-color-light-rgb: 244, 244, 244; 73 | --ion-color-light-contrast: #000000; 74 | --ion-color-light-contrast-rgb: 0, 0, 0; 75 | --ion-color-light-shade: #d7d8da; 76 | --ion-color-light-tint: #f5f6f9; 77 | } 78 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "target": "es5", 13 | "typeRoots": [ 14 | "node_modules/@types" 15 | ], 16 | "lib": [ 17 | "es2018", 18 | "dom" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /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-spacing": true, 20 | "indent": [ 21 | true, 22 | "spaces" 23 | ], 24 | "interface-over-type-literal": true, 25 | "label-position": true, 26 | "max-line-length": [ 27 | true, 28 | 140 29 | ], 30 | "member-access": false, 31 | "member-ordering": [ 32 | true, 33 | { 34 | "order": [ 35 | "static-field", 36 | "instance-field", 37 | "static-method", 38 | "instance-method" 39 | ] 40 | } 41 | ], 42 | "no-arg": true, 43 | "no-bitwise": true, 44 | "no-console": [ 45 | true, 46 | "debug", 47 | "info", 48 | "time", 49 | "timeEnd", 50 | "trace" 51 | ], 52 | "no-construct": true, 53 | "no-debugger": true, 54 | "no-duplicate-super": true, 55 | "no-empty": false, 56 | "no-empty-interface": true, 57 | "no-eval": true, 58 | "no-inferrable-types": [ 59 | true, 60 | "ignore-params" 61 | ], 62 | "no-misused-new": true, 63 | "no-non-null-assertion": true, 64 | "no-shadowed-variable": true, 65 | "no-string-literal": false, 66 | "no-string-throw": true, 67 | "no-switch-case-fall-through": true, 68 | "no-trailing-whitespace": true, 69 | "no-unnecessary-initializer": true, 70 | "no-unused-expression": true, 71 | "no-use-before-declare": true, 72 | "no-var-keyword": true, 73 | "object-literal-sort-keys": false, 74 | "one-line": [ 75 | true, 76 | "check-open-brace", 77 | "check-catch", 78 | "check-else", 79 | "check-whitespace" 80 | ], 81 | "prefer-const": true, 82 | "quotemark": [ 83 | true, 84 | "single" 85 | ], 86 | "radix": true, 87 | "semicolon": [ 88 | true, 89 | "always" 90 | ], 91 | "triple-equals": [ 92 | true, 93 | "allow-null-check" 94 | ], 95 | "typedef-whitespace": [ 96 | true, 97 | { 98 | "call-signature": "nospace", 99 | "index-signature": "nospace", 100 | "parameter": "nospace", 101 | "property-declaration": "nospace", 102 | "variable-declaration": "nospace" 103 | } 104 | ], 105 | "unified-signatures": true, 106 | "variable-name": false, 107 | "whitespace": [ 108 | true, 109 | "check-branch", 110 | "check-decl", 111 | "check-operator", 112 | "check-separator", 113 | "check-type" 114 | ], 115 | "directive-selector": [ 116 | true, 117 | "attribute", 118 | "app", 119 | "camelCase" 120 | ], 121 | "component-selector": [ 122 | true, 123 | "element", 124 | "app", 125 | "page", 126 | "kebab-case" 127 | ], 128 | "no-output-on-prefix": true, 129 | "use-input-property-decorator": true, 130 | "use-output-property-decorator": true, 131 | "use-host-property-decorator": true, 132 | "no-input-rename": true, 133 | "no-output-rename": true, 134 | "use-life-cycle-interface": true, 135 | "use-pipe-transform-interface": true, 136 | "directive-class-suffix": true 137 | } 138 | } 139 | --------------------------------------------------------------------------------