├── .browserslistrc
├── .editorconfig
├── .gitignore
├── README.md
├── angular.json
├── e2e
├── protractor.conf.js
├── src
│ ├── app.e2e-spec.ts
│ └── app.po.ts
└── tsconfig.e2e.json
├── package-lock.json
├── package.json
├── src
├── app
│ ├── app.component.css
│ ├── app.component.html
│ ├── app.component.spec.ts
│ ├── app.component.ts
│ ├── app.module.ts
│ └── customer
│ │ ├── country.model.ts
│ │ ├── customer-address
│ │ ├── countries.service.ts
│ │ ├── customer-address.component.css
│ │ ├── customer-address.component.html
│ │ ├── customer-address.component.spec.ts
│ │ └── customer-address.component.ts
│ │ ├── customer-basic
│ │ ├── customer-basic.component.css
│ │ ├── customer-basic.component.html
│ │ ├── customer-basic.component.spec.ts
│ │ └── customer-basic.component.ts
│ │ ├── customer-credit-cards
│ │ ├── customer-credit-cards.component.css
│ │ ├── customer-credit-cards.component.html
│ │ ├── customer-credit-cards.component.spec.ts
│ │ └── customer-credit-cards.component.ts
│ │ ├── customer-master
│ │ ├── customer-master.component.css
│ │ ├── customer-master.component.html
│ │ ├── customer-master.component.spec.ts
│ │ └── customer-master.component.ts
│ │ ├── customer.module.spec.ts
│ │ └── customer.module.ts
├── assets
│ ├── .gitkeep
│ └── angular_athens.jpeg
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── index.html
├── karma.conf.js
├── main.ts
├── polyfills.ts
├── styles.css
├── test.ts
├── tsconfig.app.json
├── tsconfig.spec.json
└── tslint.json
├── tsconfig.json
├── tslint.json
└── yarn.lock
/.browserslistrc:
--------------------------------------------------------------------------------
1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 | #
5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed
6 |
7 | > 0.5%
8 | last 2 versions
9 | Firefox ESR
10 | not dead
11 | not IE 9-11
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 |
8 | # dependencies
9 | /node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | yarn-error.log
34 | testem.log
35 | /typings
36 |
37 | # System Files
38 | .DS_Store
39 | Thumbs.db
40 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Reactive Forms w/ Smart Dumb Components
2 |
3 | This code has been created for a presentation in which I show:
4 | - A comparison between Reactive and Template Driven Forms
5 | - The basics of the Reactive Forms
6 | - How to approach a Reactive Form using a Smart-Dumb pattern
7 |
8 | ## Slides
9 |
10 | [Here](https://slides.com/profanis/deck-c1edf6) you can find the slides of my talk
11 |
12 | ## Related Article
13 |
14 | https://profanis.weebly.com/blog/smart-dumb-in-nested-reactive-forms
15 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "nested-forms-validation": {
7 | "root": "",
8 | "sourceRoot": "src",
9 | "projectType": "application",
10 | "prefix": "app",
11 | "schematics": {},
12 | "architect": {
13 | "build": {
14 | "builder": "@angular-devkit/build-angular:browser",
15 | "options": {
16 | "aot": true,
17 | "outputPath": "dist/nested-forms-validation",
18 | "index": "src/index.html",
19 | "main": "src/main.ts",
20 | "polyfills": "src/polyfills.ts",
21 | "tsConfig": "src/tsconfig.app.json",
22 | "assets": [
23 | "src/favicon.ico",
24 | "src/assets"
25 | ],
26 | "styles": [
27 | "src/styles.css"
28 | ],
29 | "scripts": []
30 | },
31 | "configurations": {
32 | "production": {
33 | "budgets": [
34 | {
35 | "type": "anyComponentStyle",
36 | "maximumWarning": "6kb"
37 | }
38 | ],
39 | "fileReplacements": [
40 | {
41 | "replace": "src/environments/environment.ts",
42 | "with": "src/environments/environment.prod.ts"
43 | }
44 | ],
45 | "optimization": true,
46 | "outputHashing": "all",
47 | "sourceMap": false,
48 | "extractCss": true,
49 | "namedChunks": false,
50 | "aot": true,
51 | "extractLicenses": true,
52 | "vendorChunk": false,
53 | "buildOptimizer": true
54 | }
55 | }
56 | },
57 | "serve": {
58 | "builder": "@angular-devkit/build-angular:dev-server",
59 | "options": {
60 | "browserTarget": "nested-forms-validation:build"
61 | },
62 | "configurations": {
63 | "production": {
64 | "browserTarget": "nested-forms-validation:build:production"
65 | }
66 | }
67 | },
68 | "extract-i18n": {
69 | "builder": "@angular-devkit/build-angular:extract-i18n",
70 | "options": {
71 | "browserTarget": "nested-forms-validation:build"
72 | }
73 | },
74 | "test": {
75 | "builder": "@angular-devkit/build-angular:karma",
76 | "options": {
77 | "main": "src/test.ts",
78 | "polyfills": "src/polyfills.ts",
79 | "tsConfig": "src/tsconfig.spec.json",
80 | "karmaConfig": "src/karma.conf.js",
81 | "styles": [
82 | "src/styles.css"
83 | ],
84 | "scripts": [],
85 | "assets": [
86 | "src/favicon.ico",
87 | "src/assets"
88 | ]
89 | }
90 | },
91 | "lint": {
92 | "builder": "@angular-devkit/build-angular:tslint",
93 | "options": {
94 | "tsConfig": [
95 | "src/tsconfig.app.json",
96 | "src/tsconfig.spec.json"
97 | ],
98 | "exclude": [
99 | "**/node_modules/**"
100 | ]
101 | }
102 | }
103 | }
104 | },
105 | "nested-forms-validation-e2e": {
106 | "root": "e2e/",
107 | "projectType": "application",
108 | "architect": {
109 | "e2e": {
110 | "builder": "@angular-devkit/build-angular:protractor",
111 | "options": {
112 | "protractorConfig": "e2e/protractor.conf.js",
113 | "devServerTarget": "nested-forms-validation:serve"
114 | },
115 | "configurations": {
116 | "production": {
117 | "devServerTarget": "nested-forms-validation:serve:production"
118 | }
119 | }
120 | },
121 | "lint": {
122 | "builder": "@angular-devkit/build-angular:tslint",
123 | "options": {
124 | "tsConfig": "e2e/tsconfig.e2e.json",
125 | "exclude": [
126 | "**/node_modules/**"
127 | ]
128 | }
129 | }
130 | }
131 | }
132 | },
133 | "defaultProject": "nested-forms-validation"
134 | }
--------------------------------------------------------------------------------
/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './src/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: require('path').join(__dirname, './tsconfig.e2e.json')
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
--------------------------------------------------------------------------------
/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 |
3 | describe('workspace-project App', () => {
4 | let page: AppPage;
5 |
6 | beforeEach(() => {
7 | page = new AppPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('Welcome to nested-forms-validation!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('app-root h1')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nested-forms-validation",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e"
11 | },
12 | "private": true,
13 | "dependencies": {
14 | "@angular/animations": "^10.2.1",
15 | "@angular/common": "^10.2.1",
16 | "@angular/compiler": "^10.2.1",
17 | "@angular/core": "^10.2.1",
18 | "@angular/forms": "^10.2.1",
19 | "@angular/platform-browser": "^10.2.1",
20 | "@angular/platform-browser-dynamic": "^10.2.1",
21 | "@angular/router": "^10.2.1",
22 | "bootstrap": "^4.1.3",
23 | "core-js": "^2.5.4",
24 | "rxjs": "~6.6.3",
25 | "tslib": "^2.0.0",
26 | "zone.js": "~0.10.2"
27 | },
28 | "devDependencies": {
29 | "@angular-devkit/build-angular": "~0.1002.0",
30 | "@angular/cli": "~10.2.0",
31 | "@angular/compiler-cli": "^10.2.1",
32 | "@angular/language-service": "^10.2.1",
33 | "@types/jasmine": "~2.8.8",
34 | "@types/jasminewd2": "~2.0.3",
35 | "@types/node": "^12.11.1",
36 | "codelyzer": "^5.1.2",
37 | "jasmine-core": "~3.5.0",
38 | "jasmine-spec-reporter": "~5.0.0",
39 | "karma": "~5.0.0",
40 | "karma-chrome-launcher": "~3.1.0",
41 | "karma-coverage-istanbul-reporter": "~3.0.2",
42 | "karma-jasmine": "~4.0.0",
43 | "karma-jasmine-html-reporter": "^1.5.0",
44 | "protractor": "~7.0.0",
45 | "ts-node": "~7.0.0",
46 | "tslint": "~6.1.0",
47 | "typescript": "~4.0.5"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/app/app.component.css:
--------------------------------------------------------------------------------
1 | .footer {
2 | position: absolute;
3 | bottom: 0;
4 | width: 100%;
5 | height: 60px;
6 | line-height: 60px;
7 | background-color: #f5f5f5;
8 | }
9 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
4 |
7 |
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { CustomerModule } from "./customer/customer.module";
2 | import { TestBed, async } from "@angular/core/testing";
3 | import { AppComponent } from "./app.component";
4 |
5 | describe("AppComponent", () => {
6 | beforeEach(async(() => {
7 | TestBed.configureTestingModule({
8 | imports: [CustomerModule],
9 | declarations: [AppComponent]
10 | }).compileComponents();
11 | }));
12 |
13 | it("should create the app", () => {
14 | const fixture = TestBed.createComponent(AppComponent);
15 | const app = fixture.debugElement.componentInstance;
16 | expect(app).toBeTruthy();
17 | });
18 | });
19 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.css']
7 | })
8 | export class AppComponent {
9 | title = 'nested-forms-validation';
10 | }
11 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from "@angular/platform-browser";
2 | import { NgModule } from "@angular/core";
3 |
4 | import { AppComponent } from "./app.component";
5 | import { CustomerModule } from "./customer/customer.module";
6 | import { HttpClientModule } from "@angular/common/http";
7 |
8 | @NgModule({
9 | declarations: [AppComponent],
10 | imports: [BrowserModule, CustomerModule, HttpClientModule],
11 | providers: [],
12 | bootstrap: [AppComponent]
13 | })
14 | export class AppModule {}
15 |
--------------------------------------------------------------------------------
/src/app/customer/country.model.ts:
--------------------------------------------------------------------------------
1 | export interface CountryModel {
2 | name: string;
3 | code: string;
4 | }
5 |
--------------------------------------------------------------------------------
/src/app/customer/customer-address/countries.service.ts:
--------------------------------------------------------------------------------
1 | import { HttpClient } from "@angular/common/http";
2 | import { Injectable } from "@angular/core";
3 | import { Observable } from "rxjs";
4 | import { map } from "rxjs/operators";
5 |
6 | import { CountryModel } from "../country.model";
7 |
8 | @Injectable({
9 | providedIn: "root"
10 | })
11 | export class CountryService {
12 | private endpoint = "https://restcountries.eu/rest/v2";
13 |
14 | constructor(private http: HttpClient) {}
15 |
16 | getCounties(): Observable {
17 | return this.http.get(this.endpoint).pipe(
18 | map((countries: any[]) =>
19 | countries.map(country => ({
20 | name: country.name,
21 | code: country.alpha2Code
22 | }))
23 | )
24 | );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/app/customer/customer-address/customer-address.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profanis/angular-athens-reactive-forms/d60ba3bd9f70597e88ec4a8e15897974de7cd949/src/app/customer/customer-address/customer-address.component.css
--------------------------------------------------------------------------------
/src/app/customer/customer-address/customer-address.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
15 |
16 |
17 |
23 |
24 |
25 |
26 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/app/customer/customer-address/customer-address.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from "@angular/core/testing";
2 |
3 | import { ReactiveFormsModule } from "@angular/forms";
4 | import { CustomerDetailComponent } from "./customer-address.component";
5 |
6 | describe("CustomerDetailComponent", () => {
7 | let component: CustomerDetailComponent;
8 | let fixture: ComponentFixture;
9 |
10 | beforeEach(async(() => {
11 | TestBed.configureTestingModule({
12 | imports: [ReactiveFormsModule],
13 | declarations: [CustomerDetailComponent]
14 | }).compileComponents();
15 | }));
16 |
17 | beforeEach(() => {
18 | fixture = TestBed.createComponent(CustomerDetailComponent);
19 | component = fixture.componentInstance;
20 | // fixture.detectChanges();
21 | });
22 |
23 | it("should create", () => {
24 | expect(component).toBeTruthy();
25 | });
26 | });
27 |
--------------------------------------------------------------------------------
/src/app/customer/customer-address/customer-address.component.ts:
--------------------------------------------------------------------------------
1 | import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
2 | import { FormGroup, FormBuilder, Validators } from '@angular/forms';
3 |
4 | import { CountryModel } from '../country.model';
5 |
6 | @Component({
7 | selector: 'app-customer-address',
8 | templateUrl: './customer-address.component.html',
9 | styleUrls: ['./customer-address.component.css'],
10 | changeDetection: ChangeDetectionStrategy.OnPush
11 | })
12 | export class CustomerDetailComponent implements OnInit {
13 |
14 | addressFormGroup: FormGroup;
15 |
16 | @Input()
17 | countries: CountryModel[];
18 |
19 | constructor(private fb: FormBuilder) {}
20 |
21 | ngOnInit(): void {
22 | this.addressFormGroup = this.initAddressFormModel();
23 | }
24 |
25 | private initAddressFormModel() {
26 | return this.fb.group({
27 | street: [, Validators.required],
28 | number: [, [Validators.required, Validators.min(0)]],
29 | postal: [, Validators.required],
30 | country: []
31 | });
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/app/customer/customer-basic/customer-basic.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profanis/angular-athens-reactive-forms/d60ba3bd9f70597e88ec4a8e15897974de7cd949/src/app/customer/customer-basic/customer-basic.component.css
--------------------------------------------------------------------------------
/src/app/customer/customer-basic/customer-basic.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 |
14 |
15 |
21 |
22 |
23 |
24 |
35 |
36 |
37 |
38 |
44 |
45 |
46 |
47 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/app/customer/customer-basic/customer-basic.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { CustomerBasicComponent } from './customer-basic.component';
4 |
5 | describe('CustomerBasicComponent', () => {
6 | let component: CustomerBasicComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ CustomerBasicComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(CustomerBasicComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/app/customer/customer-basic/customer-basic.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3 |
4 | @Component({
5 | selector: 'app-customer-basic',
6 | templateUrl: './customer-basic.component.html',
7 | styleUrls: ['./customer-basic.component.css']
8 | })
9 | export class CustomerBasicComponent implements OnInit {
10 |
11 | basicFormGroup: FormGroup;
12 |
13 | constructor(private fb: FormBuilder) {}
14 |
15 | ngOnInit(): void {
16 | this.basicFormGroup = this.initBasicFormModel();
17 | }
18 |
19 | private initBasicFormModel() {
20 | return this.fb.group({
21 | firstName: [, Validators.required],
22 | lastName: [, Validators.required],
23 | age: [, Validators.min(0)],
24 | gender: [],
25 | email: [, [Validators.required, Validators.email]],
26 | phone: this.fb.group({
27 | areaCode: [],
28 | phoneNumber: []
29 | })
30 | });
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/app/customer/customer-credit-cards/customer-credit-cards.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profanis/angular-athens-reactive-forms/d60ba3bd9f70597e88ec4a8e15897974de7cd949/src/app/customer/customer-credit-cards/customer-credit-cards.component.css
--------------------------------------------------------------------------------
/src/app/customer/customer-credit-cards/customer-credit-cards.component.html:
--------------------------------------------------------------------------------
1 |
2 |
34 |
--------------------------------------------------------------------------------
/src/app/customer/customer-credit-cards/customer-credit-cards.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { CustomerCreditCardsComponent } from './customer-credit-cards.component';
4 |
5 | describe('CustomerCreditCardsComponent', () => {
6 | let component: CustomerCreditCardsComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ CustomerCreditCardsComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(CustomerCreditCardsComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/app/customer/customer-credit-cards/customer-credit-cards.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, OnInit } from '@angular/core';
2 | import { FormArray, FormBuilder, Validators } from '@angular/forms';
3 |
4 | @Component({
5 | selector: 'app-customer-credit-cards',
6 | templateUrl: './customer-credit-cards.component.html',
7 | styleUrls: ['./customer-credit-cards.component.css']
8 | })
9 | export class CustomerCreditCardsComponent implements OnInit {
10 |
11 | creditCardsFormArray: FormArray;
12 |
13 | constructor(private fb: FormBuilder) {}
14 |
15 | ngOnInit() {
16 | this.creditCardsFormArray = this.fb.array([
17 | this.initCreditCard()
18 | ]);
19 | }
20 |
21 |
22 | addCreditCard() {
23 | const control = this.creditCardsFormArray;
24 | control.push(this.initCreditCard());
25 | }
26 |
27 | removeCreditCard(index: number) {
28 | const control = this.creditCardsFormArray;
29 | control.removeAt(index);
30 | }
31 |
32 |
33 | showDeleteButton(index: number) {
34 | return index > 0 || this.creditCardsFormArray.length === 1;
35 | }
36 |
37 |
38 | private initCreditCard() {
39 | return this.fb.group({
40 | cardAlias: [, Validators.required],
41 | cardHolderName: [, Validators.required],
42 | cardNumber: [, Validators.required],
43 | ccv: [, Validators.required]
44 | });
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/app/customer/customer-master/customer-master.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profanis/angular-athens-reactive-forms/d60ba3bd9f70597e88ec4a8e15897974de7cd949/src/app/customer/customer-master/customer-master.component.css
--------------------------------------------------------------------------------
/src/app/customer/customer-master/customer-master.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
20 |
21 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/app/customer/customer-master/customer-master.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from "@angular/core/testing";
2 |
3 | import { CustomerMasterComponent } from "./customer-master.component";
4 | import { ReactiveFormsModule } from "@angular/forms";
5 | import { CustomerDetailComponent } from "../customer-address/customer-address.component";
6 |
7 | describe("CustomerMasterComponent", () => {
8 | let component: CustomerMasterComponent;
9 | let fixture: ComponentFixture;
10 |
11 | beforeEach(async(() => {
12 | TestBed.configureTestingModule({
13 | imports: [ReactiveFormsModule],
14 | declarations: [CustomerMasterComponent, CustomerDetailComponent]
15 | }).compileComponents();
16 | }));
17 |
18 | beforeEach(() => {
19 | fixture = TestBed.createComponent(CustomerMasterComponent);
20 | component = fixture.componentInstance;
21 | fixture.detectChanges();
22 | });
23 |
24 | it("should create", () => {
25 | expect(component).toBeTruthy();
26 | });
27 |
28 | it("should have a valid form", () => {
29 | // const firstName = component.theForm.get("firstName");
30 | });
31 | });
32 |
--------------------------------------------------------------------------------
/src/app/customer/customer-master/customer-master.component.ts:
--------------------------------------------------------------------------------
1 | import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
2 | import { combineLatest, Observable } from 'rxjs';
3 | import { map } from 'rxjs/operators';
4 | import { CountryService } from '../customer-address/countries.service';
5 | import { CustomerDetailComponent } from '../customer-address/customer-address.component';
6 | import { CustomerBasicComponent } from '../customer-basic/customer-basic.component';
7 | import { CustomerCreditCardsComponent } from '../customer-credit-cards/customer-credit-cards.component';
8 |
9 |
10 | @Component({
11 | selector: 'app-customer-master',
12 | templateUrl: './customer-master.component.html',
13 | styleUrls: ['./customer-master.component.css']
14 | })
15 | export class CustomerMasterComponent implements OnInit, AfterViewInit {
16 |
17 | formIsValid$: Observable;
18 | countries$: Observable;
19 |
20 | @ViewChild(CustomerBasicComponent, { static: true }) customerBasicComponent;
21 | @ViewChild(CustomerCreditCardsComponent, { static: true }) customerCreditCardsComponent;
22 | @ViewChild(CustomerDetailComponent, { static: true }) customerDetailComponent;
23 |
24 | constructor(
25 | private countryService: CountryService
26 | ) {}
27 |
28 | ngOnInit() {
29 | this.countries$ = this.countryService.getCounties();
30 | }
31 |
32 | ngAfterViewInit(): void {
33 | const statusIsTrue = map(status => status === 'VALID');
34 |
35 | const basicFormStatus = this.customerBasicComponent.basicFormGroup.statusChanges.pipe(
36 | statusIsTrue
37 | );
38 |
39 | const creditCardFormStatus = this.customerCreditCardsComponent.creditCardsFormArray.statusChanges.pipe(
40 | statusIsTrue
41 | );
42 |
43 | const addressFormStatus = this.customerDetailComponent.addressFormGroup.statusChanges.pipe(
44 | statusIsTrue
45 | );
46 |
47 | this.formIsValid$ = combineLatest([basicFormStatus,
48 | addressFormStatus,
49 | creditCardFormStatus]).pipe(
50 | map((statuses) => statuses.every(status => status === true))
51 | );
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/app/customer/customer.module.spec.ts:
--------------------------------------------------------------------------------
1 | import { CustomerModule } from './customer.module';
2 |
3 | describe('CustomerModule', () => {
4 | let customerModule: CustomerModule;
5 |
6 | beforeEach(() => {
7 | customerModule = new CustomerModule();
8 | });
9 |
10 | it('should create an instance', () => {
11 | expect(customerModule).toBeTruthy();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/src/app/customer/customer.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from "@angular/core";
2 | import { CommonModule } from "@angular/common";
3 | import { ReactiveFormsModule } from "@angular/forms";
4 | import { CustomerMasterComponent } from "./customer-master/customer-master.component";
5 | import { CustomerDetailComponent } from "./customer-address/customer-address.component";
6 | import { CustomerCreditCardsComponent } from './customer-credit-cards/customer-credit-cards.component';
7 | import { CustomerBasicComponent } from './customer-basic/customer-basic.component';
8 |
9 | @NgModule({
10 | imports: [CommonModule, ReactiveFormsModule],
11 | declarations: [CustomerMasterComponent, CustomerDetailComponent, CustomerCreditCardsComponent, CustomerBasicComponent],
12 | exports: [CustomerMasterComponent]
13 | })
14 | export class CustomerModule {}
15 |
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profanis/angular-athens-reactive-forms/d60ba3bd9f70597e88ec4a8e15897974de7cd949/src/assets/.gitkeep
--------------------------------------------------------------------------------
/src/assets/angular_athens.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profanis/angular-athens-reactive-forms/d60ba3bd9f70597e88ec4a8e15897974de7cd949/src/assets/angular_athens.jpeg
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false
7 | };
8 |
9 | /*
10 | * For easier debugging in development mode, you can import the following file
11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
12 | *
13 | * This import should be commented out in production mode because it will have a negative impact
14 | * on performance if an error is thrown.
15 | */
16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
17 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profanis/angular-athens-reactive-forms/d60ba3bd9f70597e88ec4a8e15897974de7cd949/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NestedFormsValidation
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, '../coverage'),
20 | reports: ['html', 'lcovonly'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false
30 | });
31 | };
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
14 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | /**
5 | * Web Animations `@angular/platform-browser/animations`
6 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
7 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
8 | **/
9 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
10 |
11 | /**
12 | * By default, zone.js will patch all possible macroTask and DomEvents
13 | * user can disable parts of macroTask/DomEvents patch by setting following flags
14 | */
15 |
16 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
17 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
18 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
19 |
20 | /*
21 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
22 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
23 | */
24 | // (window as any).__Zone_enable_cross_context_check = true;
25 |
26 | /***************************************************************************************************
27 | * Zone JS is required by default for Angular itself.
28 | */
29 | import 'zone.js/dist/zone'; // Included with Angular CLI.
30 |
31 |
32 |
33 | /***************************************************************************************************
34 | * APPLICATION IMPORTS
35 | */
36 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
3 | @import "~bootstrap/dist/css/bootstrap.css";
4 |
5 | body {
6 | font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande",
7 | "Lucida Sans", Arial, sans-serif;
8 | margin: 0;
9 | padding: 0;
10 | }
11 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: any;
11 |
12 | // First, initialize the Angular testing environment.
13 | getTestBed().initTestEnvironment(
14 | BrowserDynamicTestingModule,
15 | platformBrowserDynamicTesting()
16 | );
17 | // Then we find all the tests.
18 | const context = require.context('./', true, /\.spec\.ts$/);
19 | // And load the modules.
20 | context.keys().map(context);
21 |
--------------------------------------------------------------------------------
/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "types": []
6 | },
7 | "files": [
8 | "main.ts",
9 | "polyfills.ts"
10 | ],
11 | "include": [
12 | "src/**/*.d.ts"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tslint.json",
3 | "rules": {
4 | "directive-selector": [
5 | true,
6 | "attribute",
7 | "app",
8 | "camelCase"
9 | ],
10 | "component-selector": [
11 | true,
12 | "element",
13 | "app",
14 | "kebab-case"
15 | ]
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "downlevelIteration": true,
6 | "importHelpers": true,
7 | "outDir": "./dist/out-tsc",
8 | "sourceMap": true,
9 | "declaration": false,
10 | "module": "es2020",
11 | "moduleResolution": "node",
12 | "emitDecoratorMetadata": true,
13 | "experimentalDecorators": true,
14 | "target": "es2015",
15 | "typeRoots": [
16 | "node_modules/@types"
17 | ],
18 | "lib": [
19 | "es2017",
20 | "dom"
21 | ]
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "deprecation": {
15 | "severity": "warn"
16 | },
17 | "eofline": true,
18 | "forin": true,
19 | "import-blacklist": [
20 | true,
21 | "rxjs/Rx"
22 | ],
23 | "import-spacing": true,
24 | "indent": [
25 | true,
26 | "spaces"
27 | ],
28 | "interface-over-type-literal": true,
29 | "label-position": true,
30 | "max-line-length": [
31 | true,
32 | 140
33 | ],
34 | "member-access": false,
35 | "member-ordering": [
36 | true,
37 | {
38 | "order": [
39 | "static-field",
40 | "instance-field",
41 | "static-method",
42 | "instance-method"
43 | ]
44 | }
45 | ],
46 | "no-arg": true,
47 | "no-bitwise": true,
48 | "no-console": [
49 | true,
50 | "debug",
51 | "info",
52 | "time",
53 | "timeEnd",
54 | "trace"
55 | ],
56 | "no-construct": true,
57 | "no-debugger": true,
58 | "no-duplicate-super": true,
59 | "no-empty": false,
60 | "no-empty-interface": true,
61 | "no-eval": true,
62 | "no-inferrable-types": [
63 | true,
64 | "ignore-params"
65 | ],
66 | "no-misused-new": true,
67 | "no-non-null-assertion": true,
68 | "no-redundant-jsdoc": true,
69 | "no-shadowed-variable": true,
70 | "no-string-literal": false,
71 | "no-string-throw": true,
72 | "no-switch-case-fall-through": true,
73 | "no-trailing-whitespace": true,
74 | "no-unnecessary-initializer": true,
75 | "no-unused-expression": true,
76 | "no-var-keyword": true,
77 | "object-literal-sort-keys": false,
78 | "one-line": [
79 | true,
80 | "check-open-brace",
81 | "check-catch",
82 | "check-else",
83 | "check-whitespace"
84 | ],
85 | "prefer-const": true,
86 | "quotemark": [
87 | true,
88 | "single"
89 | ],
90 | "radix": true,
91 | "semicolon": [
92 | true,
93 | "always"
94 | ],
95 | "triple-equals": [
96 | true,
97 | "allow-null-check"
98 | ],
99 | "typedef-whitespace": [
100 | true,
101 | {
102 | "call-signature": "nospace",
103 | "index-signature": "nospace",
104 | "parameter": "nospace",
105 | "property-declaration": "nospace",
106 | "variable-declaration": "nospace"
107 | }
108 | ],
109 | "unified-signatures": true,
110 | "variable-name": false,
111 | "whitespace": [
112 | true,
113 | "check-branch",
114 | "check-decl",
115 | "check-operator",
116 | "check-separator",
117 | "check-type"
118 | ],
119 | "no-output-on-prefix": true,
120 | "no-inputs-metadata-property": true,
121 | "no-outputs-metadata-property": true,
122 | "no-host-metadata-property": true,
123 | "no-input-rename": true,
124 | "no-output-rename": true,
125 | "use-lifecycle-interface": true,
126 | "use-pipe-transform-interface": true,
127 | "component-class-suffix": true,
128 | "directive-class-suffix": true
129 | }
130 | }
131 |
--------------------------------------------------------------------------------