Skip to content

Add modules, components, routes #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/about/about.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="container">
<p>
This project shows you how to do things in Angular with full diff examples in commits/pull requests, with instructions included.
</p>
</div>
Empty file.
25 changes: 25 additions & 0 deletions src/app/about/about.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { AboutComponent } from './about.component';

describe('AboutComponent', () => {
let component: AboutComponent;
let fixture: ComponentFixture<AboutComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AboutComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AboutComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions src/app/about/about.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.scss']
})
export class AboutComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
13 changes: 13 additions & 0 deletions src/app/about/about.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AboutModule } from './about.module';

describe('AboutModule', () => {
let aboutModule: AboutModule;

beforeEach(() => {
aboutModule = new AboutModule();
});

it('should create an instance', () => {
expect(aboutModule).toBeTruthy();
});
});
11 changes: 11 additions & 0 deletions src/app/about/about.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import { AboutComponent } from './about.component';
import { RoutingModule } from './about.router';

@NgModule({
imports: [RoutingModule, CommonModule],
declarations: [AboutComponent],
})
export class AboutModule {}
12 changes: 12 additions & 0 deletions src/app/about/about.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RouterModule, Routes } from '@angular/router';

import { AboutComponent } from './about.component';

const routes: Routes = [
{
path: '',
component: AboutComponent,
},
];

export const RoutingModule = RouterModule.forChild(routes);
8 changes: 8 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ <h1>
</div>
</div>

<nav>
<ul>
<li><a routerLink="about" routerLinkActive="active">About</a></li>
<li><a routerLink="contact" routerLinkActive="active">Contact</a></li>
<li><a routerLink="heroes" routerLinkActive="active">Heroes</a></li>
<li><a routerLink="tutorials" routerLinkActive="active">Tutorials</a></li>
</ul>
</nav>
<hr />

<router-outlet></router-outlet>
7 changes: 7 additions & 0 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nav {
a {
&.active {
font-weight: bold;
}
}
}
26 changes: 21 additions & 5 deletions src/app/app.router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { RouterModule, Routes } from '@angular/router';

import { LayoutComponent } from './shared/layout/layout.component';

const routes: Routes = [
Expand All @@ -8,9 +8,25 @@ const routes: Routes = [
{
path: '',
component: LayoutComponent,
children: [
{ path: 'tutorials', loadChildren: 'app/tutorials/tutorials.module#TutorialsModule' },
],
children: [{ path: 'about', loadChildren: 'app/about/about.module#AboutModule' }],
},

{
path: '',
component: LayoutComponent,
children: [{ path: 'contact', loadChildren: 'app/contact/contact.module#ContactModule' }],
},

{
path: '',
component: LayoutComponent,
children: [{ path: 'heroes', loadChildren: 'app/heroes/heroes.module#HeroesModule' }],
},

{
path: '',
component: LayoutComponent,
children: [{ path: 'tutorials', loadChildren: 'app/tutorials/tutorials.module#TutorialsModule' }],
},
];

Expand Down
4 changes: 4 additions & 0 deletions src/app/contact/contact.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h2>I would love to get your feedback</h2>
<small>Disclaimer: this is just a mock form. If you want to contact me you can open an issue.</small>

<app-form></app-form>
Empty file.
25 changes: 25 additions & 0 deletions src/app/contact/contact.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ContactComponent } from './contact.component';

describe('ContactComponent', () => {
let component: ContactComponent;
let fixture: ComponentFixture<ContactComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ContactComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ContactComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions src/app/contact/contact.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-contact',
templateUrl: './contact.component.html',
styleUrls: ['./contact.component.scss']
})
export class ContactComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
13 changes: 13 additions & 0 deletions src/app/contact/contact.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ContactModule } from './contact.module';

describe('ContactModule', () => {
let contactModule: ContactModule;

beforeEach(() => {
contactModule = new ContactModule();
});

it('should create an instance', () => {
expect(contactModule).toBeTruthy();
});
});
13 changes: 13 additions & 0 deletions src/app/contact/contact.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';

import { ContactComponent } from './contact.component';
import { RoutingModule } from './contact.router';
import { FormComponent } from './form/form.component';

@NgModule({
imports: [RoutingModule, CommonModule, ReactiveFormsModule],
declarations: [ContactComponent, FormComponent],
})
export class ContactModule {}
12 changes: 12 additions & 0 deletions src/app/contact/contact.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RouterModule, Routes } from '@angular/router';

import { ContactComponent } from './contact.component';

const routes: Routes = [
{
path: '',
component: ContactComponent,
},
];

export const RoutingModule = RouterModule.forChild(routes);
14 changes: 14 additions & 0 deletions src/app/contact/form/form.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<form (ngSubmit)="submit()" [formGroup]="contactForm">
<div class="form-group">
<label for="email"></label>
<input type="email" formControlName="email" class="form-control" name="email" id="email" aria-describedby="email-aria" placeholder="Your email">
<small id="email-aria" hidden>Your email</small>
</div>

<div class="form-group">
<label for="message">Your message</label>
<textarea formControlName="message" class="form-control" name="message" id="message" rows="3"></textarea>
</div>

<button type="submit" class="btn btn-primary">Send</button>
</form>
Empty file.
25 changes: 25 additions & 0 deletions src/app/contact/form/form.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { FormComponent } from './form.component';

describe('FormComponent', () => {
let component: FormComponent;
let fixture: ComponentFixture<FormComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ FormComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(FormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
25 changes: 25 additions & 0 deletions src/app/contact/form/form.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';

@Component({
selector: 'app-form',
templateUrl: './form.component.html',
styleUrls: ['./form.component.scss']
})
export class FormComponent {
contactForm = this.formBuilder.group({
email: this.formBuilder.control('', [Validators.required, Validators.email]),
message: this.formBuilder.control('', Validators.required),
});

constructor(private formBuilder: FormBuilder) { }

submit() {
if (this.contactForm.invalid) {
alert('the form is wrong');
return;
}

alert('hey, thanks!');
}
}
3 changes: 3 additions & 0 deletions src/app/heroes/heroes.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
heroes works!
</p>
Empty file.
25 changes: 25 additions & 0 deletions src/app/heroes/heroes.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { HeroesComponent } from './heroes.component';

describe('HeroesComponent', () => {
let component: HeroesComponent;
let fixture: ComponentFixture<HeroesComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HeroesComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(HeroesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions src/app/heroes/heroes.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
styleUrls: ['./heroes.component.scss']
})
export class HeroesComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
13 changes: 13 additions & 0 deletions src/app/heroes/heroes.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { HeroesModule } from './heroes.module';

describe('HeroesModule', () => {
let heroesModule: HeroesModule;

beforeEach(() => {
heroesModule = new HeroesModule();
});

it('should create an instance', () => {
expect(heroesModule).toBeTruthy();
});
});
11 changes: 11 additions & 0 deletions src/app/heroes/heroes.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import { HeroesComponent } from './heroes.component';
import { RoutingModule } from './heroes.router';

@NgModule({
imports: [RoutingModule, CommonModule],
declarations: [HeroesComponent],
})
export class HeroesModule {}
12 changes: 12 additions & 0 deletions src/app/heroes/heroes.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RouterModule, Routes } from '@angular/router';

import { HeroesComponent } from './heroes.component';

const routes: Routes = [
{
path: '',
component: HeroesComponent,
},
];

export const RoutingModule = RouterModule.forChild(routes);
4 changes: 3 additions & 1 deletion src/app/shared/layout/layout.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="container-fluid">
<fieldset>
<legend>LayoutComponent</legend>
<router-outlet></router-outlet>
<div class="container">
<router-outlet></router-outlet>
</div>
</fieldset>
</div>
Loading