861 lines
26 KiB
HTML
861 lines
26 KiB
HTML
<html lang="en"><head></head><body><form id="mainForm" method="post" action="http://plnkr.co/edit/?p=preview" target="_self"><input type="hidden" name="files[app/app.component.3.ts]" value="import { Component } from '@angular/core';
|
|
|
|
@Component({
|
|
selector: 'my-app',
|
|
template: `
|
|
<app-title [subtitle]="subtitle"></app-title>
|
|
<nav>
|
|
<a routerLink="contact" routerLinkActive="active">Contact</a>
|
|
<a routerLink="crisis" routerLinkActive="active">Crisis Center</a>
|
|
<a routerLink="heroes" routerLinkActive="active">Heroes</a>
|
|
</nav>
|
|
<router-outlet></router-outlet>
|
|
`
|
|
})
|
|
export class AppComponent {
|
|
subtitle = '(v3)';
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/app.module.3.ts]" value="import { NgModule } from '@angular/core';
|
|
import { BrowserModule } from '@angular/platform-browser';
|
|
|
|
/* App Root */
|
|
import { AppComponent } from './app.component.3';
|
|
import { HighlightDirective } from './highlight.directive';
|
|
import { TitleComponent } from './title.component';
|
|
import { UserService } from './user.service';
|
|
|
|
/* Feature Modules */
|
|
import { ContactModule } from './contact/contact.module.3';
|
|
|
|
/* Routing Module */
|
|
import { AppRoutingModule } from './app-routing.module.3';
|
|
|
|
@NgModule({
|
|
imports: [
|
|
BrowserModule,
|
|
ContactModule,
|
|
AppRoutingModule
|
|
],
|
|
providers: [ UserService ],
|
|
declarations: [ AppComponent, HighlightDirective, TitleComponent ],
|
|
bootstrap: [ AppComponent ]
|
|
})
|
|
export class AppModule { }
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/app-routing.module.3.ts]" value="import { NgModule } from '@angular/core';
|
|
import { Routes, RouterModule } from '@angular/router';
|
|
|
|
export const routes: Routes = [
|
|
{ path: '', redirectTo: 'contact', pathMatch: 'full'},
|
|
{ path: 'crisis', loadChildren: 'app/crisis/crisis.module#CrisisModule' },
|
|
{ path: 'heroes', loadChildren: 'app/hero/hero.module.3#HeroModule' }
|
|
];
|
|
|
|
@NgModule({
|
|
imports: [RouterModule.forRoot(routes)],
|
|
exports: [RouterModule]
|
|
})
|
|
export class AppRoutingModule {}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/highlight.directive.ts]" value="import { Directive, ElementRef } from '@angular/core';
|
|
|
|
@Directive({ selector: '[highlight]' })
|
|
/** Highlight the attached element in gold */
|
|
export class HighlightDirective {
|
|
constructor(el: ElementRef) {
|
|
el.nativeElement.style.backgroundColor = 'gold';
|
|
console.log(
|
|
`* AppRoot highlight called for ${el.nativeElement.tagName}`);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/title.component.html]" value="<h1 highlight>{{title}} {{subtitle}}</h1>
|
|
<p *ngIf="user">
|
|
<i>Welcome, {{user}}</i>
|
|
<p>
|
|
|
|
|
|
|
|
<!--
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
-->"><input type="hidden" name="files[app/title.component.ts]" value="import { Component, Input } from '@angular/core';
|
|
import { UserService } from './user.service';
|
|
|
|
@Component({
|
|
moduleId: module.id,
|
|
selector: 'app-title',
|
|
templateUrl: './title.component.html',
|
|
})
|
|
export class TitleComponent {
|
|
@Input() subtitle = '';
|
|
title = 'Angular Modules';
|
|
user = '';
|
|
|
|
constructor(userService: UserService) {
|
|
this.user = userService.userName;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/user.service.ts]" value="import { Injectable } from '@angular/core';
|
|
|
|
@Injectable()
|
|
/** Dummy version of an authenticated user service */
|
|
export class UserService {
|
|
userName = 'Sherlock Holmes';
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/contact/contact.component.css]" value=".ng-valid[required] {
|
|
border-left: 5px solid #42A948; /* green */
|
|
}
|
|
|
|
.ng-invalid {
|
|
border-left: 5px solid #a94442; /* red */
|
|
}
|
|
|
|
.alert {
|
|
padding: 15px;
|
|
margin: 8px 0;
|
|
border: 1px solid transparent;
|
|
border-radius: 4px;
|
|
}
|
|
.alert-danger {
|
|
color: #a94442;
|
|
background-color: #f2dede;
|
|
border-color: #ebccd1;
|
|
}
|
|
|
|
.msg {
|
|
color: blue;
|
|
background-color: whitesmoke;
|
|
border: 1px solid transparent;
|
|
border-radius: 4px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/contact/contact.component.html]" value="<h2>Contact of {{userName}}</h2>
|
|
<div *ngIf="msg" class="msg">{{msg}}</div>
|
|
|
|
<form *ngIf="contacts" (ngSubmit)="onSubmit()" #contactForm="ngForm">
|
|
<h3 highlight>{{ contact.name | awesome }}</h3>
|
|
<div class="form-group">
|
|
<label for="name">Name</label>
|
|
<input type="text" class="form-control" required
|
|
[(ngModel)]="contact.name"
|
|
name="name" #name="ngModel" >
|
|
<div [hidden]="name.valid" class="alert alert-danger">
|
|
Name is required
|
|
</div>
|
|
</div>
|
|
<br>
|
|
<button type="submit" class="btn btn-default" [disabled]="!contactForm.form.valid">Save</button>
|
|
<button type="button" class="btn" (click)="next()" [disabled]="!contactForm.form.valid">Next Contact</button>
|
|
<button type="button" class="btn" (click)="newContact()">New Contact</button>
|
|
</form>
|
|
|
|
|
|
<!--
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
-->"><input type="hidden" name="files[app/contact/contact.service.ts]" value="import { Injectable } from '@angular/core';
|
|
|
|
export class Contact {
|
|
constructor(public id: number, public name: string) { }
|
|
}
|
|
|
|
const CONTACTS: Contact[] = [
|
|
new Contact(21, 'Sam Spade'),
|
|
new Contact(22, 'Nick Danger'),
|
|
new Contact(23, 'Nancy Drew')
|
|
];
|
|
|
|
const FETCH_LATENCY = 500;
|
|
|
|
@Injectable()
|
|
export class ContactService {
|
|
|
|
getContacts() {
|
|
return new Promise<Contact[]>(resolve => {
|
|
setTimeout(() => { resolve(CONTACTS); }, FETCH_LATENCY);
|
|
});
|
|
}
|
|
|
|
getContact(id: number | string) {
|
|
return this.getContacts()
|
|
.then(heroes => heroes.find(hero => hero.id === +id));
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/contact/awesome.pipe.ts]" value="import { Pipe, PipeTransform } from '@angular/core';
|
|
|
|
@Pipe({ name: 'awesome' })
|
|
/** Precede the input string with the word "Awesome " */
|
|
export class AwesomePipe implements PipeTransform {
|
|
transform(phrase: string) {
|
|
return phrase ? 'Awesome ' + phrase : '';
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/contact/contact.component.3.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
|
|
import { Contact, ContactService } from './contact.service';
|
|
import { UserService } from '../user.service';
|
|
|
|
@Component({
|
|
moduleId: module.id,
|
|
selector: 'app-contact',
|
|
templateUrl: './contact.component.html',
|
|
styleUrls: [ './contact.component.css' ]
|
|
})
|
|
export class ContactComponent implements OnInit {
|
|
contact: Contact;
|
|
contacts: Contact[];
|
|
|
|
msg = 'Loading contacts ...';
|
|
userName = '';
|
|
|
|
constructor(private contactService: ContactService, userService: UserService) {
|
|
this.userName = userService.userName;
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.contactService.getContacts().then(contacts => {
|
|
this.msg = '';
|
|
this.contacts = contacts;
|
|
this.contact = contacts[0];
|
|
});
|
|
}
|
|
|
|
next() {
|
|
let ix = 1 + this.contacts.indexOf(this.contact);
|
|
if (ix >= this.contacts.length) { ix = 0; }
|
|
this.contact = this.contacts[ix];
|
|
}
|
|
|
|
onSubmit() {
|
|
// POST-DEMO TODO: do something like save it
|
|
this.displayMessage('Saved ' + this.contact.name);
|
|
}
|
|
|
|
newContact() {
|
|
this.displayMessage('New contact');
|
|
this.contact = {id: 42, name: ''};
|
|
this.contacts.push(this.contact);
|
|
}
|
|
|
|
/** Display a message briefly, then remove it. */
|
|
displayMessage(msg: string) {
|
|
this.msg = msg;
|
|
setTimeout(() => this.msg = '', 1500);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/contact/contact.module.3.ts]" value="import { NgModule } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
import { AwesomePipe } from './awesome.pipe';
|
|
|
|
import { ContactComponent } from './contact.component.3';
|
|
import { ContactService } from './contact.service';
|
|
import { HighlightDirective } from './highlight.directive';
|
|
|
|
import { ContactRoutingModule } from './contact-routing.module.3';
|
|
|
|
@NgModule({
|
|
imports: [ CommonModule, FormsModule, ContactRoutingModule ],
|
|
declarations: [ ContactComponent, HighlightDirective, AwesomePipe ],
|
|
providers: [ ContactService ]
|
|
})
|
|
export class ContactModule { }
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/contact/contact-routing.module.3.ts]" value="import { NgModule } from '@angular/core';
|
|
import { RouterModule } from '@angular/router';
|
|
|
|
import { ContactComponent } from './contact.component.3';
|
|
|
|
@NgModule({
|
|
imports: [RouterModule.forChild([
|
|
{ path: 'contact', component: ContactComponent}
|
|
])],
|
|
exports: [RouterModule]
|
|
})
|
|
export class ContactRoutingModule {}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/contact/highlight.directive.ts]" value="/* tslint:disable */
|
|
// Same directive name and selector as
|
|
// HighlightDirective in parent AppModule
|
|
// It selects for both input boxes and 'highlight' attr
|
|
// and it highlights in blue instead of gold
|
|
|
|
import { Directive, ElementRef } from '@angular/core';
|
|
|
|
@Directive({ selector: '[highlight], input' })
|
|
/** Highlight the attached element or an InputElement in blue */
|
|
export class HighlightDirective {
|
|
constructor(el: ElementRef) {
|
|
el.nativeElement.style.backgroundColor = 'powderblue';
|
|
console.log(
|
|
`* Contact highlight called for ${el.nativeElement.tagName}`);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/crisis/crisis-detail.component.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
@Component({
|
|
template: `
|
|
<h3 highlight>Crisis Detail</h3>
|
|
<div>Crisis id: {{id}}</div>
|
|
<br>
|
|
<a routerLink="../list">Crisis List</a>
|
|
`
|
|
})
|
|
export class CrisisDetailComponent implements OnInit {
|
|
id: number;
|
|
constructor(private route: ActivatedRoute) { }
|
|
|
|
ngOnInit() {
|
|
this.id = parseInt(this.route.snapshot.params['id'], 10);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/crisis/crisis-list.component.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
|
|
import { Crisis,
|
|
CrisisService } from './crisis.service';
|
|
|
|
@Component({
|
|
template: `
|
|
<h3 highlight>Crisis List</h3>
|
|
<div *ngFor='let crisis of crisises | async'>
|
|
<a routerLink="{{'../' + crisis.id}}">{{crisis.id}} - {{crisis.name}}</a>
|
|
</div>
|
|
`
|
|
})
|
|
export class CrisisListComponent implements OnInit {
|
|
crisises: Promise<Crisis[]>;
|
|
|
|
constructor(private crisisService: CrisisService) { }
|
|
|
|
ngOnInit() {
|
|
this.crisises = this.crisisService.getCrises();
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/crisis/crisis-routing.module.ts]" value="import { NgModule } from '@angular/core';
|
|
import { Routes,
|
|
RouterModule } from '@angular/router';
|
|
|
|
import { CrisisListComponent } from './crisis-list.component';
|
|
import { CrisisDetailComponent } from './crisis-detail.component';
|
|
|
|
const routes: Routes = [
|
|
{ path: '', redirectTo: 'list', pathMatch: 'full'},
|
|
{ path: 'list', component: CrisisListComponent },
|
|
{ path: ':id', component: CrisisDetailComponent }
|
|
];
|
|
|
|
@NgModule({
|
|
imports: [RouterModule.forChild(routes)],
|
|
exports: [RouterModule]
|
|
})
|
|
export class CrisisRoutingModule {}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/crisis/crisis.module.ts]" value="import { NgModule } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
import { CrisisListComponent } from './crisis-list.component';
|
|
import { CrisisDetailComponent } from './crisis-detail.component';
|
|
import { CrisisService } from './crisis.service';
|
|
import { CrisisRoutingModule } from './crisis-routing.module';
|
|
|
|
@NgModule({
|
|
imports: [ CommonModule, CrisisRoutingModule ],
|
|
declarations: [ CrisisDetailComponent, CrisisListComponent ],
|
|
providers: [ CrisisService ]
|
|
})
|
|
export class CrisisModule {}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/crisis/crisis.service.ts]" value="import { Injectable } from '@angular/core';
|
|
|
|
export class Crisis {
|
|
constructor(public id: number, public name: string) { }
|
|
}
|
|
|
|
const CRISES: Crisis[] = [
|
|
new Crisis(1, 'Dragon Burning Cities'),
|
|
new Crisis(2, 'Sky Rains Great White Sharks'),
|
|
new Crisis(3, 'Giant Asteroid Heading For Earth'),
|
|
new Crisis(4, 'Procrastinators Meeting Delayed Again'),
|
|
];
|
|
|
|
const FETCH_LATENCY = 500;
|
|
|
|
@Injectable()
|
|
export class CrisisService {
|
|
|
|
getCrises() {
|
|
return new Promise<Crisis[]>(resolve => {
|
|
setTimeout(() => { resolve(CRISES); }, FETCH_LATENCY);
|
|
});
|
|
}
|
|
|
|
getCrisis(id: number | string) {
|
|
return this.getCrises()
|
|
.then(heroes => heroes.find(hero => hero.id === +id));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/hero/hero-detail.component.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
import { Hero,
|
|
HeroService } from './hero.service';
|
|
|
|
@Component({
|
|
template: `
|
|
<h3 highlight>Hero Detail</h3>
|
|
<div *ngIf="hero">
|
|
<div>Id: {{hero.id}}</div><br>
|
|
<label>Name:
|
|
<input [(ngModel)]="hero.name">
|
|
</label>
|
|
</div>
|
|
<br>
|
|
<a routerLink="../">Hero List</a>
|
|
`
|
|
})
|
|
export class HeroDetailComponent implements OnInit {
|
|
hero: Hero;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private heroService: HeroService) { }
|
|
|
|
ngOnInit() {
|
|
let id = parseInt(this.route.snapshot.params['id'], 10);
|
|
this.heroService.getHero(id).then(hero => this.hero = hero);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/hero/hero-list.component.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
|
|
import { Hero,
|
|
HeroService } from './hero.service';
|
|
|
|
@Component({
|
|
template: `
|
|
<h3 highlight>Hero List</h3>
|
|
<div *ngFor='let hero of heroes | async'>
|
|
<a routerLink="{{hero.id}}">{{hero.id}} - {{hero.name}}</a>
|
|
</div>
|
|
`
|
|
})
|
|
export class HeroListComponent implements OnInit {
|
|
heroes: Promise<Hero[]>;
|
|
constructor(private heroService: HeroService) { }
|
|
|
|
ngOnInit() {
|
|
this.heroes = this.heroService.getHeroes();
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/hero/hero.service.ts]" value="import { Injectable } from '@angular/core';
|
|
|
|
export class Hero {
|
|
constructor(public id: number, public name: string) { }
|
|
}
|
|
|
|
const HEROES: Hero[] = [
|
|
new Hero(11, 'Mr. Nice'),
|
|
new Hero(12, 'Narco'),
|
|
new Hero(13, 'Bombasto'),
|
|
new Hero(14, 'Celeritas'),
|
|
new Hero(15, 'Magneta'),
|
|
new Hero(16, 'RubberMan')
|
|
];
|
|
|
|
const FETCH_LATENCY = 500;
|
|
|
|
@Injectable()
|
|
export class HeroService {
|
|
|
|
getHeroes() {
|
|
return new Promise<Hero[]>(resolve => {
|
|
setTimeout(() => { resolve(HEROES); }, FETCH_LATENCY);
|
|
});
|
|
}
|
|
|
|
getHero(id: number | string) {
|
|
return this.getHeroes()
|
|
.then(heroes => heroes.find(hero => hero.id === +id));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/hero/hero.component.3.ts]" value="import { Component } from '@angular/core';
|
|
|
|
import { HeroService } from './hero.service';
|
|
import { UserService } from '../user.service';
|
|
|
|
@Component({
|
|
template: `
|
|
<h2>Heroes of {{userName}}</h2>
|
|
<router-outlet></router-outlet>
|
|
`,
|
|
providers: [ HeroService ]
|
|
})
|
|
export class HeroComponent {
|
|
userName = '';
|
|
constructor(userService: UserService) {
|
|
this.userName = userService.userName;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/hero/hero.module.3.ts]" value="import { NgModule } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
import { HeroComponent } from './hero.component.3';
|
|
import { HeroDetailComponent } from './hero-detail.component';
|
|
import { HeroListComponent } from './hero-list.component';
|
|
import { HighlightDirective } from './highlight.directive';
|
|
import { HeroRoutingModule } from './hero-routing.module.3';
|
|
|
|
@NgModule({
|
|
imports: [ CommonModule, FormsModule, HeroRoutingModule ],
|
|
declarations: [
|
|
HeroComponent, HeroDetailComponent, HeroListComponent,
|
|
HighlightDirective
|
|
]
|
|
})
|
|
export class HeroModule { }
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/hero/hero-routing.module.3.ts]" value="import { NgModule } from '@angular/core';
|
|
import { Routes,
|
|
RouterModule } from '@angular/router';
|
|
|
|
import { HeroComponent } from './hero.component.3';
|
|
import { HeroListComponent } from './hero-list.component';
|
|
import { HeroDetailComponent } from './hero-detail.component';
|
|
|
|
const routes: Routes = [
|
|
{ path: '',
|
|
component: HeroComponent,
|
|
children: [
|
|
{ path: '', component: HeroListComponent },
|
|
{ path: ':id', component: HeroDetailComponent }
|
|
]
|
|
}
|
|
];
|
|
|
|
@NgModule({
|
|
imports: [RouterModule.forChild(routes)],
|
|
exports: [RouterModule]
|
|
})
|
|
export class HeroRoutingModule {}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[app/hero/highlight.directive.ts]" value="import { Directive, ElementRef } from '@angular/core';
|
|
|
|
// Same directive name and selector as
|
|
// HighlightDirective in parent AppRootModule
|
|
// It selects for both input boxes and 'highlight' attr
|
|
// and it highlights in beige instead of yellow
|
|
@Directive({ selector: '[highlight]' })
|
|
export class HighlightDirective {
|
|
constructor(el: ElementRef) {
|
|
el.nativeElement.style.backgroundColor = 'beige';
|
|
console.log(`* Hero highlight called for ${el.nativeElement.tagName}`);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[main.3.ts]" value="import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
|
import { AppModule } from './app/app.module.3';
|
|
|
|
platformBrowserDynamic().bootstrapModule(AppModule);
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[styles.css]" value="/* Master Styles */
|
|
h1 {
|
|
color: #369;
|
|
font-family: Arial, Helvetica, sans-serif;
|
|
font-size: 250%;
|
|
}
|
|
h2, h3 {
|
|
color: #444;
|
|
font-family: Arial, Helvetica, sans-serif;
|
|
font-weight: lighter;
|
|
}
|
|
body {
|
|
margin: 2em;
|
|
}
|
|
body, input[text], button {
|
|
color: #888;
|
|
font-family: Cambria, Georgia;
|
|
}
|
|
a {
|
|
cursor: pointer;
|
|
cursor: hand;
|
|
}
|
|
button {
|
|
font-family: Arial;
|
|
background-color: #eee;
|
|
border: none;
|
|
padding: 5px 10px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
cursor: hand;
|
|
}
|
|
button:hover {
|
|
background-color: #cfd8dc;
|
|
}
|
|
button:disabled {
|
|
background-color: #eee;
|
|
color: #aaa;
|
|
cursor: auto;
|
|
}
|
|
|
|
/* Navigation link styles */
|
|
nav a {
|
|
padding: 5px 10px;
|
|
text-decoration: none;
|
|
margin-right: 10px;
|
|
margin-top: 10px;
|
|
display: inline-block;
|
|
background-color: #eee;
|
|
border-radius: 4px;
|
|
}
|
|
nav a:visited, a:link {
|
|
color: #607D8B;
|
|
}
|
|
nav a:hover {
|
|
color: #039be5;
|
|
background-color: #CFD8DC;
|
|
}
|
|
nav a.active {
|
|
color: #039be5;
|
|
}
|
|
|
|
/* items class */
|
|
.items {
|
|
margin: 0 0 2em 0;
|
|
list-style-type: none;
|
|
padding: 0;
|
|
width: 24em;
|
|
}
|
|
.items li {
|
|
cursor: pointer;
|
|
position: relative;
|
|
left: 0;
|
|
background-color: #EEE;
|
|
margin: .5em;
|
|
padding: .3em 0;
|
|
height: 1.6em;
|
|
border-radius: 4px;
|
|
}
|
|
.items li:hover {
|
|
color: #607D8B;
|
|
background-color: #DDD;
|
|
left: .1em;
|
|
}
|
|
.items li.selected {
|
|
background-color: #CFD8DC;
|
|
color: white;
|
|
}
|
|
.items li.selected:hover {
|
|
background-color: #BBD8DC;
|
|
}
|
|
.items .text {
|
|
position: relative;
|
|
top: -3px;
|
|
}
|
|
.items .badge {
|
|
display: inline-block;
|
|
font-size: small;
|
|
color: white;
|
|
padding: 0.8em 0.7em 0 0.7em;
|
|
background-color: #607D8B;
|
|
line-height: 1em;
|
|
position: relative;
|
|
left: -1px;
|
|
top: -4px;
|
|
height: 1.8em;
|
|
margin-right: .8em;
|
|
border-radius: 4px 0 0 4px;
|
|
}
|
|
/* everywhere else */
|
|
* {
|
|
font-family: Arial, Helvetica, sans-serif;
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
*/"><input type="hidden" name="files[index.html]" value="<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<script>document.write('<base href="' + document.location + '" />');</script>
|
|
<title>NgModule - Contact</title>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="stylesheet" href="styles.css">
|
|
|
|
<!-- Polyfills -->
|
|
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
|
|
|
|
<script src="https://unpkg.com/zone.js@0.7.4?main=browser"></script>
|
|
<script src="https://unpkg.com/systemjs@0.19.39/dist/system.src.js"></script>
|
|
<script src="https://cdn.rawgit.com/angular/angular.io/b3c65a9/public/docs/_examples/_boilerplate/systemjs.config.web.js"></script>
|
|
<script>
|
|
System.import('main.3.js').catch(function(err){ console.error(err); });
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<my-app>Loading...</my-app>
|
|
</body>
|
|
</html>
|
|
|
|
|
|
<!--
|
|
Copyright 2016 Google Inc. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at http://angular.io/license
|
|
-->"><input type="hidden" name="tags[0]" value="angular"><input type="hidden" name="tags[1]" value="example"><input type="hidden" name="tags[2]" value="NgModule"><input type="hidden" name="private" value="true"><input type="hidden" name="description" value="Angular Example - NgModule v.3"></form><script>document.getElementById("mainForm").submit();</script></body></html> |