491 lines
14 KiB
HTML
491 lines
14 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.2.ts]" value="import { Component } from '@angular/core';
|
|
|
|
@Component({
|
|
selector: 'my-app',
|
|
template: `
|
|
<app-title [subtitle]="subtitle"></app-title>
|
|
<app-contact></app-contact>
|
|
`
|
|
})
|
|
export class AppComponent {
|
|
subtitle = '(v2)';
|
|
}
|
|
|
|
|
|
/*
|
|
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.2.ts]" value="import { NgModule } from '@angular/core';
|
|
import { BrowserModule } from '@angular/platform-browser';
|
|
|
|
/* App Root */
|
|
import
|
|
{ AppComponent } from './app.component.2';
|
|
/*
|
|
{ AppComponent } from './app.component';
|
|
*/
|
|
import { HighlightDirective } from './highlight.directive';
|
|
import { TitleComponent } from './title.component';
|
|
import { UserService } from './user.service';
|
|
|
|
/* Contact Imports */
|
|
import
|
|
{ ContactModule } from './contact/contact.module.2';
|
|
/*
|
|
{ ContactModule } from './contact/contact.module';
|
|
*/
|
|
|
|
@NgModule({
|
|
imports: [ BrowserModule, ContactModule ],
|
|
declarations: [ AppComponent, HighlightDirective, TitleComponent ],
|
|
providers: [ UserService ],
|
|
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/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.2.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';
|
|
/*
|
|
{ ContactComponent } from './contact.component';
|
|
*/
|
|
import { ContactService } from './contact.service';
|
|
import { HighlightDirective } from './highlight.directive';
|
|
|
|
@NgModule({
|
|
imports: [ CommonModule, FormsModule ],
|
|
declarations: [ ContactComponent, HighlightDirective, AwesomePipe ],
|
|
exports: [ 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/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[main.2.ts]" value="import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
|
import { AppModule } from './app/app.module.2';
|
|
|
|
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.2.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 - Contact NgModule v.2"></form><script>document.getElementById("mainForm").submit();</script></body></html> |