909 lines
27 KiB
HTML
909 lines
27 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.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 = '(Final)';
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
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.ts]" value="import { NgModule } from '@angular/core';
|
||
|
import { BrowserModule } from '@angular/platform-browser';
|
||
|
|
||
|
/* App Root */
|
||
|
import { AppComponent } from './app.component';
|
||
|
|
||
|
/* Feature Modules */
|
||
|
import { ContactModule } from './contact/contact.module';
|
||
|
import { CoreModule } from './core/core.module';
|
||
|
|
||
|
/* Routing Module */
|
||
|
import { AppRoutingModule } from './app-routing.module';
|
||
|
|
||
|
@NgModule({
|
||
|
imports: [
|
||
|
BrowserModule,
|
||
|
ContactModule,
|
||
|
/*
|
||
|
CoreModule,
|
||
|
*/
|
||
|
CoreModule.forRoot({userName: 'Miss Marple'}),
|
||
|
AppRoutingModule
|
||
|
],
|
||
|
declarations: [ AppComponent ],
|
||
|
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.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#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/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/contact.component.ts]" value="// Exact copy except import UserService from core
|
||
|
import { Component, OnInit } from '@angular/core';
|
||
|
|
||
|
import { Contact, ContactService } from './contact.service';
|
||
|
import { UserService } from '../core/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.ts]" value="import { NgModule } from '@angular/core';
|
||
|
import { SharedModule } from '../shared/shared.module';
|
||
|
|
||
|
import { ContactComponent } from './contact.component';
|
||
|
import { ContactService } from './contact.service';
|
||
|
import { ContactRoutingModule } from './contact-routing.module';
|
||
|
|
||
|
@NgModule({
|
||
|
imports: [ SharedModule, ContactRoutingModule ],
|
||
|
declarations: [ ContactComponent ],
|
||
|
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.ts]" value="import { NgModule } from '@angular/core';
|
||
|
import { RouterModule } from '@angular/router';
|
||
|
|
||
|
import { ContactComponent } from './contact.component';
|
||
|
|
||
|
@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/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.ts]" value="// Exact copy except import UserService from core
|
||
|
import { Component } from '@angular/core';
|
||
|
|
||
|
import { HeroService } from './hero.service';
|
||
|
import { UserService } from '../core/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.ts]" value="import { NgModule } from '@angular/core';
|
||
|
|
||
|
import { SharedModule } from '../shared/shared.module';
|
||
|
|
||
|
import { HeroComponent } from './hero.component';
|
||
|
import { HeroDetailComponent } from './hero-detail.component';
|
||
|
import { HeroListComponent } from './hero-list.component';
|
||
|
import { HeroRoutingModule } from './hero-routing.module';
|
||
|
|
||
|
@NgModule({
|
||
|
imports: [ SharedModule, HeroRoutingModule ],
|
||
|
declarations: [
|
||
|
HeroComponent, HeroDetailComponent, HeroListComponent,
|
||
|
]
|
||
|
})
|
||
|
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.ts]" value="import { NgModule } from '@angular/core';
|
||
|
import { Routes,
|
||
|
RouterModule } from '@angular/router';
|
||
|
|
||
|
import { HeroComponent } from './hero.component';
|
||
|
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/core/title.component.html]" value="<!-- Exact copy from earlier app.component.html -->
|
||
|
<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/core/core.module.ts]" value="/* tslint:disable:member-ordering no-unused-variable */
|
||
|
import {
|
||
|
ModuleWithProviders, NgModule,
|
||
|
Optional, SkipSelf } from '@angular/core';
|
||
|
|
||
|
import { CommonModule } from '@angular/common';
|
||
|
|
||
|
import { TitleComponent } from './title.component';
|
||
|
import { UserService } from './user.service';
|
||
|
import { UserServiceConfig } from './user.service';
|
||
|
|
||
|
@NgModule({
|
||
|
imports: [ CommonModule ],
|
||
|
declarations: [ TitleComponent ],
|
||
|
exports: [ TitleComponent ],
|
||
|
providers: [ UserService ]
|
||
|
})
|
||
|
export class CoreModule {
|
||
|
|
||
|
constructor (@Optional() @SkipSelf() parentModule: CoreModule) {
|
||
|
if (parentModule) {
|
||
|
throw new Error(
|
||
|
'CoreModule is already loaded. Import it in the AppModule only');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static forRoot(config: UserServiceConfig): ModuleWithProviders {
|
||
|
return {
|
||
|
ngModule: CoreModule,
|
||
|
providers: [
|
||
|
{provide: UserServiceConfig, useValue: config }
|
||
|
]
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
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/core/title.component.ts]" value="// Exact copy of app/title.component.ts except import UserService from shared
|
||
|
import { Component, Input } from '@angular/core';
|
||
|
import { UserService } from '../core/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/core/user.service.ts]" value="// Crazy copy of the app/user.service
|
||
|
// Proves that UserService is an app-wide singleton and only instantiated once
|
||
|
// IFF shared.module follows the `forRoot` pattern
|
||
|
//
|
||
|
// If it didn't, a new instance of UserService would be created
|
||
|
// after each lazy load and the userName would double up.
|
||
|
|
||
|
import { Injectable, Optional } from '@angular/core';
|
||
|
|
||
|
let nextId = 1;
|
||
|
|
||
|
export class UserServiceConfig {
|
||
|
userName = 'Philip Marlowe';
|
||
|
}
|
||
|
|
||
|
@Injectable()
|
||
|
export class UserService {
|
||
|
id = nextId++;
|
||
|
private _userName = 'Sherlock Holmes';
|
||
|
|
||
|
constructor(@Optional() config: UserServiceConfig) {
|
||
|
if (config) { this._userName = config.userName; }
|
||
|
}
|
||
|
|
||
|
get userName() {
|
||
|
// Demo: add a suffix if this service has been created more than once
|
||
|
const suffix = this.id > 1 ? ` times ${this.id}` : '';
|
||
|
return this._userName + suffix;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
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/shared/awesome.pipe.ts]" value="// Exact copy of contact.awesome.pipe
|
||
|
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/shared/highlight.directive.ts]" value="/* tslint:disable */
|
||
|
// Exact copy of contact/highlight.directive except for color and message
|
||
|
import { Directive, ElementRef } from '@angular/core';
|
||
|
|
||
|
@Directive({ selector: '[highlight], input' })
|
||
|
/** Highlight the attached element or an InputElement in gray */
|
||
|
export class HighlightDirective {
|
||
|
constructor(el: ElementRef) {
|
||
|
el.nativeElement.style.backgroundColor = 'lightgray';
|
||
|
console.log(
|
||
|
`* Shared 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/shared/shared.module.ts]" value="import { NgModule } from '@angular/core';
|
||
|
import { CommonModule } from '@angular/common';
|
||
|
import { FormsModule } from '@angular/forms';
|
||
|
|
||
|
import { AwesomePipe } from './awesome.pipe';
|
||
|
import { HighlightDirective } from './highlight.directive';
|
||
|
|
||
|
@NgModule({
|
||
|
imports: [ CommonModule ],
|
||
|
declarations: [ AwesomePipe, HighlightDirective ],
|
||
|
exports: [ AwesomePipe, HighlightDirective,
|
||
|
CommonModule, FormsModule ]
|
||
|
})
|
||
|
export class SharedModule { }
|
||
|
|
||
|
|
||
|
/*
|
||
|
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.ts]" value="// The browser platform with a compiler
|
||
|
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||
|
|
||
|
// The app module
|
||
|
import { AppModule } from './app/app.module';
|
||
|
|
||
|
// Compile and launch the module
|
||
|
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 Deluxe</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.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 Final"></form><script>document.getElementById("mainForm").submit();</script></body></html>
|