├── .angular-cli.json ├── .editorconfig ├── .gitignore ├── README.md ├── e2e ├── app.e2e-spec.ts ├── app.po.ts └── tsconfig.e2e.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── protractor.conf.js ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.sass │ ├── app.component.ts │ ├── app.module.ts │ ├── loading-spinner │ │ ├── loading-spinner.component.html │ │ ├── loading-spinner.component.sass │ │ └── loading-spinner.component.ts │ ├── pagination.service.ts │ └── scrollable.directive.ts ├── assets │ └── .gitkeep ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.sass ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── typings.d.ts ├── tsconfig.json └── tslint.json /.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "base" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "", 21 | "styles": [ 22 | "styles.sass" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json", 40 | "exclude": "**/node_modules/**" 41 | }, 42 | { 43 | "project": "src/tsconfig.spec.json", 44 | "exclude": "**/node_modules/**" 45 | }, 46 | { 47 | "project": "e2e/tsconfig.e2e.json", 48 | "exclude": "**/node_modules/**" 49 | } 50 | ], 51 | "test": { 52 | "karma": { 53 | "config": "./karma.conf.js" 54 | } 55 | }, 56 | "defaults": { 57 | "styleExt": "sass", 58 | "class": { 59 | "spec": false 60 | }, 61 | "component": { 62 | "spec": false 63 | }, 64 | "directive": { 65 | "spec": false 66 | }, 67 | "guard": { 68 | "spec": false 69 | }, 70 | "module": { 71 | "spec": false 72 | }, 73 | "pipe": { 74 | "spec": false 75 | }, 76 | "service": { 77 | "spec": false 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /.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 | /src/environments/environment.prod.ts 4 | /src/environments/environment.ts 5 | NOTES.md 6 | functions/* 7 | 8 | 9 | # compiled output 10 | /dist 11 | /tmp 12 | /out-tsc 13 | 14 | # dependencies 15 | /node_modules 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | 33 | # misc 34 | /.sass-cache 35 | /connect.lock 36 | /coverage 37 | /libpeerconnection.log 38 | npm-debug.log 39 | testem.log 40 | /typings 41 | 42 | # e2e 43 | /e2e/*.js 44 | /e2e/*.map 45 | 46 | # System Files 47 | .DS_Store 48 | Thumbs.db 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Episode 62 - Infinite Scroll Pagination Firestore 2 | 3 | Watch the [infinite scroll firestore screencast](https://angularfirebase.com/lessons/infinite-scroll-firestore-angular/) 4 | 5 | ## Usage 6 | 7 | - `git clone` 8 | - create the `src/enviornments/environment.ts` file and add your firebase config to it 9 | - `npm install` 10 | - `ng serve` 11 | -------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('base 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/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/e2e", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "jasminewd2", 11 | "node" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 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/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | reports: [ 'html', 'lcovonly' ], 20 | fixWebpackSourcePaths: true 21 | }, 22 | angularCli: { 23 | environment: 'dev' 24 | }, 25 | reporters: ['progress', 'kjhtml'], 26 | port: 9876, 27 | colors: true, 28 | logLevel: config.LOG_INFO, 29 | autoWatch: true, 30 | browsers: ['Chrome'], 31 | singleRun: false 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "base", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "^4.4.6", 16 | "@angular/common": "^4.4.6", 17 | "@angular/compiler": "^4.4.6", 18 | "@angular/core": "^4.4.6", 19 | "@angular/forms": "^4.4.6", 20 | "@angular/http": "^4.4.6", 21 | "@angular/platform-browser": "^4.4.6", 22 | "@angular/platform-browser-dynamic": "^4.4.6", 23 | "@angular/platform-server": "^4.4.6", 24 | "@angular/router": "^4.4.6", 25 | "angularfire2": "^5.0.0-rc.3", 26 | "core-js": "^2.4.1", 27 | "firebase": "^4.6.0", 28 | "rxjs": "^5.4.2", 29 | "zone.js": "^0.8.14" 30 | }, 31 | "devDependencies": { 32 | "@angular/cli": "1.4.9", 33 | "@angular/compiler-cli": "^4.4.6", 34 | "@angular/language-service": "^4.2.4", 35 | "@types/jasmine": "~2.5.53", 36 | "@types/jasminewd2": "~2.0.2", 37 | "@types/node": "~6.0.60", 38 | "codelyzer": "~3.2.0", 39 | "jasmine-core": "~2.6.2", 40 | "jasmine-spec-reporter": "~4.1.0", 41 | "karma": "~1.7.0", 42 | "karma-chrome-launcher": "~2.1.1", 43 | "karma-cli": "~1.0.1", 44 | "karma-coverage-istanbul-reporter": "^1.2.1", 45 | "karma-jasmine": "~1.1.0", 46 | "karma-jasmine-html-reporter": "^0.2.2", 47 | "protractor": "~5.1.2", 48 | "ts-node": "~3.2.0", 49 | "tslint": "~5.7.0", 50 | "typescript": "~2.3.3" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /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 | './e2e/**/*.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 | -------------------------------------------------------------------------------- /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 | 6 | @NgModule({ 7 | imports: [RouterModule.forRoot(routes)], 8 | exports: [RouterModule] 9 | }) 10 | export class AppRoutingModule { } 11 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |

I ran out of boats!

5 | 6 | 7 |
8 |

Built in {{ boat.year }}

9 | 10 |
11 | 12 |
13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/app/app.component.sass: -------------------------------------------------------------------------------- 1 | .content 2 | overflow-y: scroll 3 | // border-right: 3px solid gray 4 | // border-left: 3px solid gray 5 | max-height: 100vh 6 | width: 70vw 7 | margin: auto 8 | text-align: center 9 | padding: 1em 10 | 11 | &::-webkit-scrollbar-track 12 | -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3) 13 | background-color: #F5F5F5 14 | &::-webkit-scrollbar 15 | width: 12px 16 | background-color: #F5F5F5 17 | &::-webkit-scrollbar-thumb 18 | background-color: #f27236 19 | 20 | .tag 21 | font-size: 2.2em 22 | 23 | 24 | 25 | 26 | @keyframes fadeIn 27 | @keyframes fadeIn 28 | from 29 | opacity: 0 30 | 31 | to 32 | opacity: 1 33 | 34 | 35 | .fadeIn 36 | animation-name: fadeIn 37 | 38 | .animated 39 | animation-duration: 1s 40 | animation-fill-mode: both 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Observable } from 'rxjs/Observable'; 3 | import { PaginationService } from './pagination.service'; 4 | 5 | 6 | @Component({ 7 | selector: 'app-root', 8 | templateUrl: './app.component.html', 9 | styleUrls: ['./app.component.sass'] 10 | }) 11 | export class AppComponent implements OnInit { 12 | 13 | 14 | constructor(public page: PaginationService) {} 15 | 16 | ngOnInit() { 17 | this.page.init('boats', 'year', { reverse: false, prepend: false }) 18 | } 19 | 20 | scrollHandler(e) { 21 | if (e === 'bottom') { 22 | this.page.more() 23 | } 24 | 25 | // if (e === 'top') { 26 | // this.page.more() 27 | // } 28 | } 29 | 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | 7 | import { AngularFireModule } from 'angularfire2'; 8 | import { environment } from '../environments/environment'; 9 | 10 | import { AngularFirestoreModule } from 'angularfire2/firestore'; 11 | import { AngularFireAuthModule } from 'angularfire2/auth'; 12 | import { ScrollableDirective } from './scrollable.directive'; 13 | import { LoadingSpinnerComponent } from './loading-spinner/loading-spinner.component'; 14 | import { PaginationService } from './pagination.service'; 15 | 16 | @NgModule({ 17 | declarations: [ 18 | AppComponent, 19 | ScrollableDirective, 20 | LoadingSpinnerComponent 21 | ], 22 | imports: [ 23 | BrowserModule, 24 | AppRoutingModule, 25 | AngularFireModule.initializeApp(environment.firebaseConfig), 26 | AngularFirestoreModule, 27 | AngularFireAuthModule 28 | ], 29 | providers: [PaginationService], 30 | bootstrap: [AppComponent] 31 | }) 32 | export class AppModule { } 33 | -------------------------------------------------------------------------------- /src/app/loading-spinner/loading-spinner.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
-------------------------------------------------------------------------------- /src/app/loading-spinner/loading-spinner.component.sass: -------------------------------------------------------------------------------- 1 | .spinner 2 | margin: 100px auto 3 | width: 40px 4 | height: 40px 5 | position: relative 6 | 7 | .cube1 8 | background-color: #333 9 | width: 15px 10 | height: 15px 11 | position: absolute 12 | top: 0 13 | left: 0 14 | -webkit-animation: sk-cubemove 1.8s infinite ease-in-out 15 | animation: sk-cubemove 1.8s infinite ease-in-out 16 | 17 | .cube2 18 | background-color: #333 19 | width: 15px 20 | height: 15px 21 | position: absolute 22 | top: 0 23 | left: 0 24 | -webkit-animation: sk-cubemove 1.8s infinite ease-in-out 25 | animation: sk-cubemove 1.8s infinite ease-in-out 26 | -webkit-animation-delay: -0.9s 27 | animation-delay: -0.9s 28 | 29 | @-webkit-keyframes sk-cubemove 30 | 25% 31 | -webkit-transform: translateX(42px) rotate(-90deg) scale(0.5) 32 | 33 | 50% 34 | -webkit-transform: translateX(42px) translateY(42px) rotate(-180deg) 35 | 36 | 75% 37 | -webkit-transform: translateX(0px) translateY(42px) rotate(-270deg) scale(0.5) 38 | 39 | 100% 40 | -webkit-transform: rotate(-360deg) 41 | 42 | 43 | @keyframes sk-cubemove 44 | 25% 45 | transform: translateX(42px) rotate(-90deg) scale(0.5) 46 | -webkit-transform: translateX(42px) rotate(-90deg) scale(0.5) 47 | 48 | 50% 49 | transform: translateX(42px) translateY(42px) rotate(-179deg) 50 | -webkit-transform: translateX(42px) translateY(42px) rotate(-179deg) 51 | 52 | 50.1% 53 | transform: translateX(42px) translateY(42px) rotate(-180deg) 54 | -webkit-transform: translateX(42px) translateY(42px) rotate(-180deg) 55 | 56 | 75% 57 | transform: translateX(0px) translateY(42px) rotate(-270deg) scale(0.5) 58 | -webkit-transform: translateX(0px) translateY(42px) rotate(-270deg) scale(0.5) 59 | 60 | 100% 61 | transform: rotate(-360deg) 62 | -webkit-transform: rotate(-360deg) -------------------------------------------------------------------------------- /src/app/loading-spinner/loading-spinner.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'loading-spinner', 5 | templateUrl: './loading-spinner.component.html', 6 | styleUrls: ['./loading-spinner.component.sass'] 7 | }) 8 | export class LoadingSpinnerComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/pagination.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore'; 3 | import { BehaviorSubject } from 'rxjs/BehaviorSubject'; 4 | import { Observable } from 'rxjs/Observable'; 5 | import 'rxjs/add/operator/do'; 6 | import 'rxjs/add/operator/scan'; 7 | import 'rxjs/add/operator/take'; 8 | 9 | // Options to reproduce firestore queries consistently 10 | interface QueryConfig { 11 | path: string, // path to collection 12 | field: string, // field to orderBy 13 | limit?: number, // limit per query 14 | reverse?: boolean, // reverse order? 15 | prepend?: boolean // prepend to source? 16 | } 17 | 18 | 19 | @Injectable() 20 | export class PaginationService { 21 | 22 | // Source data 23 | private _done = new BehaviorSubject(false); 24 | private _loading = new BehaviorSubject(false); 25 | private _data = new BehaviorSubject([]); 26 | 27 | private query: QueryConfig; 28 | 29 | // Observable data 30 | data: Observable; 31 | done: Observable = this._done.asObservable(); 32 | loading: Observable = this._loading.asObservable(); 33 | 34 | 35 | constructor(private afs: AngularFirestore) { } 36 | 37 | // Initial query sets options and defines the Observable 38 | init(path, field, opts?) { 39 | this.query = { 40 | path, 41 | field, 42 | limit: 2, 43 | reverse: false, 44 | prepend: false, 45 | ...opts 46 | } 47 | 48 | const first = this.afs.collection(this.query.path, ref => { 49 | return ref 50 | .orderBy(this.query.field, this.query.reverse ? 'desc' : 'asc') 51 | .limit(this.query.limit) 52 | }) 53 | 54 | this.mapAndUpdate(first) 55 | 56 | // Create the observable array for consumption in components 57 | this.data = this._data.asObservable() 58 | .scan( (acc, val) => { 59 | return this.query.prepend ? val.concat(acc) : acc.concat(val) 60 | }) 61 | } 62 | 63 | 64 | // Retrieves additional data from firestore 65 | more() { 66 | const cursor = this.getCursor() 67 | 68 | const more = this.afs.collection(this.query.path, ref => { 69 | return ref 70 | .orderBy(this.query.field, this.query.reverse ? 'desc' : 'asc') 71 | .limit(this.query.limit) 72 | .startAfter(cursor) 73 | }) 74 | this.mapAndUpdate(more) 75 | } 76 | 77 | 78 | // Determines the doc snapshot to paginate query 79 | private getCursor() { 80 | const current = this._data.value 81 | if (current.length) { 82 | return this.query.prepend ? current[0].doc : current[current.length - 1].doc 83 | } 84 | return null 85 | } 86 | 87 | 88 | // Maps the snapshot to usable format the updates source 89 | private mapAndUpdate(col: AngularFirestoreCollection) { 90 | 91 | if (this._done.value || this._loading.value) { return }; 92 | 93 | // loading 94 | this._loading.next(true) 95 | 96 | // Map snapshot with doc ref (needed for cursor) 97 | return col.snapshotChanges() 98 | .do(arr => { 99 | let values = arr.map(snap => { 100 | const data = snap.payload.doc.data() 101 | const doc = snap.payload.doc 102 | return { ...data, doc } 103 | }) 104 | 105 | // If prepending, reverse array 106 | values = this.query.prepend ? values.reverse() : values 107 | 108 | // update source with new values, done loading 109 | this._data.next(values) 110 | this._loading.next(false) 111 | 112 | // no more values, mark done 113 | if (!values.length) { 114 | this._done.next(true) 115 | } 116 | }) 117 | .take(1) 118 | .subscribe() 119 | 120 | } 121 | 122 | 123 | // Reset the page 124 | reset() { 125 | this._data.next([]) 126 | this._done.next(false) 127 | } 128 | 129 | 130 | } 131 | 132 | 133 | -------------------------------------------------------------------------------- /src/app/scrollable.directive.ts: -------------------------------------------------------------------------------- 1 | import { Directive, HostListener, EventEmitter, Output, ElementRef } from '@angular/core'; 2 | 3 | @Directive({ 4 | selector: '[scrollable]' 5 | }) 6 | export class ScrollableDirective { 7 | 8 | @Output() scrollPosition = new EventEmitter() 9 | 10 | 11 | constructor(public el: ElementRef) { } 12 | 13 | @HostListener('scroll', ['$event']) 14 | onScroll(event) { 15 | try { 16 | 17 | const top = event.target.scrollTop 18 | const height = this.el.nativeElement.scrollHeight 19 | const offset = this.el.nativeElement.offsetHeight 20 | 21 | 22 | if (top > height - offset - 1) { 23 | this.scrollPosition.emit('bottom') 24 | } 25 | 26 | if (top === 0) { 27 | this.scrollPosition.emit('top') 28 | } 29 | 30 | } catch (err) {} 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AngularFirebase/62-firestore-infinite-scroll/4eddf5e2048031d91d39edbfc7c98c3cbf3f6fe2/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AngularFirebase/62-firestore-infinite-scroll/4eddf5e2048031d91d39edbfc7c98c3cbf3f6fe2/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Base 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /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 | * Required to support Web Animations `@angular/platform-browser/animations`. 51 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 52 | **/ 53 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 54 | 55 | 56 | 57 | /*************************************************************************************************** 58 | * Zone JS is required by Angular itself. 59 | */ 60 | import 'zone.js/dist/zone'; // Included with Angular CLI. 61 | 62 | 63 | 64 | /*************************************************************************************************** 65 | * APPLICATION IMPORTS 66 | */ 67 | 68 | /** 69 | * Date, currency, decimal and percent pipes. 70 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 71 | */ 72 | // import 'intl'; // Run `npm install --save intl`. 73 | /** 74 | * Need to import at least one locale-data with intl. 75 | */ 76 | // import 'intl/locale-data/jsonp/en'; 77 | -------------------------------------------------------------------------------- /src/styles.sass: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare const __karma__: any; 17 | declare const require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "baseUrl": "./", 6 | "module": "es2015", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "target": "es5", 11 | "typeRoots": [ 12 | "node_modules/@types" 13 | ], 14 | "lib": [ 15 | "es2017", 16 | "dom" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "callable-types": true, 7 | "class-name": true, 8 | "comment-format": [ 9 | true, 10 | "check-space" 11 | ], 12 | "curly": true, 13 | "eofline": true, 14 | "forin": true, 15 | "import-blacklist": [true, "rxjs"], 16 | "import-spacing": true, 17 | "indent": [ 18 | true, 19 | "spaces" 20 | ], 21 | "interface-over-type-literal": true, 22 | "label-position": true, 23 | "max-line-length": [ 24 | true, 25 | 140 26 | ], 27 | "member-access": false, 28 | "member-ordering": [ 29 | true, 30 | "static-before-instance", 31 | "variables-before-functions" 32 | ], 33 | "no-arg": true, 34 | "no-bitwise": true, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-construct": true, 44 | "no-debugger": true, 45 | "no-duplicate-variable": true, 46 | "no-empty": false, 47 | "no-empty-interface": true, 48 | "no-eval": true, 49 | "no-inferrable-types": [true, "ignore-params"], 50 | "no-shadowed-variable": true, 51 | "no-string-literal": false, 52 | "no-string-throw": true, 53 | "no-switch-case-fall-through": true, 54 | "no-trailing-whitespace": false, 55 | "no-unused-expression": true, 56 | "no-use-before-declare": true, 57 | "no-var-keyword": true, 58 | "object-literal-sort-keys": false, 59 | "one-line": [ 60 | true, 61 | "check-open-brace", 62 | "check-catch", 63 | "check-else", 64 | "check-whitespace" 65 | ], 66 | "prefer-const": true, 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "radix": true, 72 | "semicolon": [ 73 | "always" 74 | ], 75 | "triple-equals": [ 76 | true, 77 | "allow-null-check" 78 | ], 79 | "typedef-whitespace": [ 80 | true, 81 | { 82 | "call-signature": "nospace", 83 | "index-signature": "nospace", 84 | "parameter": "nospace", 85 | "property-declaration": "nospace", 86 | "variable-declaration": "nospace" 87 | } 88 | ], 89 | "typeof-compare": true, 90 | "unified-signatures": true, 91 | "variable-name": false, 92 | "whitespace": [ 93 | true, 94 | "check-branch", 95 | "check-decl", 96 | "check-operator", 97 | "check-separator", 98 | "check-type" 99 | ], 100 | 101 | "directive-selector": [true, "attribute", "", "camelCase"], 102 | "component-selector": [true, "element", "", "kebab-case"], 103 | "use-input-property-decorator": true, 104 | "use-output-property-decorator": true, 105 | "use-host-property-decorator": true, 106 | "no-input-rename": true, 107 | "no-output-rename": true, 108 | "use-life-cycle-interface": true, 109 | "use-pipe-transform-interface": true, 110 | "component-class-suffix": true, 111 | "directive-class-suffix": true, 112 | "no-access-missing-member": true, 113 | "templates-use-public": true, 114 | "invoke-injectable": true 115 | } 116 | } 117 | --------------------------------------------------------------------------------