481 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			481 lines
		
	
	
		
			13 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: `
 | |
|     <hero-list></hero-list>
 | |
|     <sales-tax></sales-tax>
 | |
|   `
 | |
| })
 | |
| export class AppComponent { }
 | |
| 
 | |
| 
 | |
| /*
 | |
| 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 { BrowserModule }       from '@angular/platform-browser';
 | |
| import { FormsModule }         from '@angular/forms';
 | |
| import { NgModule }     from '@angular/core';
 | |
| import { AppComponent } from './app.component';
 | |
| import { HeroDetailComponent } from './hero-detail.component';
 | |
| import { HeroListComponent }   from './hero-list.component';
 | |
| import { SalesTaxComponent }   from './sales-tax.component';
 | |
| import { HeroService }         from './hero.service';
 | |
| import { BackendService }      from './backend.service';
 | |
| import { Logger }              from './logger.service';
 | |
| 
 | |
| @NgModule({
 | |
|   imports: [
 | |
|     BrowserModule,
 | |
|     FormsModule
 | |
|   ],
 | |
|   declarations: [
 | |
|     AppComponent,
 | |
|     HeroDetailComponent,
 | |
|     HeroListComponent,
 | |
|     SalesTaxComponent
 | |
|   ],
 | |
|   providers: [
 | |
|     BackendService,
 | |
|     HeroService,
 | |
|     Logger
 | |
|   ],
 | |
|   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/backend.service.ts]" value="import { Injectable, Type } from '@angular/core';
 | |
| 
 | |
| import { Logger } from './logger.service';
 | |
| import { Hero } from './hero';
 | |
| 
 | |
| const HEROES = [
 | |
|         new Hero('Windstorm', 'Weather mastery'),
 | |
|         new Hero('Mr. Nice', 'Killing them with kindness'),
 | |
|         new Hero('Magneta', 'Manipulates metalic objects')
 | |
|       ];
 | |
| 
 | |
| @Injectable()
 | |
| export class BackendService {
 | |
|   constructor(private logger: Logger) {}
 | |
| 
 | |
|   getAll(type: Type<any>): PromiseLike<any[]> {
 | |
|     if (type === Hero) {
 | |
|       // TODO get from the database
 | |
|       return Promise.resolve<Hero[]>(HEROES);
 | |
|     }
 | |
|     let err = new Error('Cannot get object of this type');
 | |
|     this.logger.error(err);
 | |
|     throw err;
 | |
|   }
 | |
| }
 | |
| 
 | |
| 
 | |
| /*
 | |
| 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-detail.component.ts]" value="import { Component, Input } from '@angular/core';
 | |
| 
 | |
| import { Hero } from './hero';
 | |
| 
 | |
| @Component({
 | |
|   moduleId: module.id,
 | |
|   selector: 'hero-detail',
 | |
|   templateUrl: './hero-detail.component.html'
 | |
| })
 | |
| export class HeroDetailComponent {
 | |
|   @Input() 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-list.component.ts]" value="import { Component, OnInit }   from '@angular/core';
 | |
| 
 | |
| import { Hero }                from './hero';
 | |
| import { HeroService }         from './hero.service';
 | |
| 
 | |
| @Component({
 | |
|   moduleId: module.id,
 | |
|   selector:    'hero-list',
 | |
|   templateUrl: './hero-list.component.html',
 | |
|   providers:  [ HeroService ]
 | |
| })
 | |
| export class HeroListComponent implements OnInit {
 | |
|   heroes: Hero[];
 | |
|   selectedHero: Hero;
 | |
| 
 | |
|   constructor(private service: HeroService) { }
 | |
| 
 | |
|   ngOnInit() {
 | |
|     this.heroes = this.service.getHeroes();
 | |
|   }
 | |
| 
 | |
|   selectHero(hero: Hero) { this.selectedHero = 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.service.ts]" value="import { Injectable } from '@angular/core';
 | |
| 
 | |
| import { Hero } from './hero';
 | |
| import { BackendService } from './backend.service';
 | |
| import { Logger } from './logger.service';
 | |
| 
 | |
| @Injectable()
 | |
| export class HeroService {
 | |
|   private heroes: Hero[] = [];
 | |
| 
 | |
|   constructor(
 | |
|     private backend: BackendService,
 | |
|     private logger: Logger) { }
 | |
| 
 | |
|   getHeroes() {
 | |
|     this.backend.getAll(Hero).then( (heroes: Hero[]) => {
 | |
|       this.logger.log(`Fetched ${heroes.length} heroes.`);
 | |
|       this.heroes.push(...heroes); // fill cache
 | |
|     });
 | |
|     return this.heroes;
 | |
|   }
 | |
| }
 | |
| 
 | |
| 
 | |
| /*
 | |
| 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.ts]" value="let nextId = 1;
 | |
| 
 | |
| export class Hero {
 | |
|   id: number;
 | |
|   constructor(
 | |
|     public name: string,
 | |
|     public power?: string) {
 | |
|       this.id = nextId++;
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 | |
| /*
 | |
| 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/logger.service.ts]" value="import { Injectable } from '@angular/core';
 | |
| 
 | |
| @Injectable()
 | |
| export class Logger {
 | |
|   log(msg: any)   { console.log(msg); }
 | |
|   error(msg: any) { console.error(msg); }
 | |
|   warn(msg: any)  { console.warn(msg); }
 | |
| }
 | |
| 
 | |
| 
 | |
| /*
 | |
| 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/mini-app.ts]" value="// A mini-application
 | |
| import { Injectable } from '@angular/core';
 | |
| 
 | |
| @Injectable()
 | |
| export class Logger {
 | |
|   log(message: string) { console.log(message); }
 | |
| }
 | |
| 
 | |
| import { Component } from '@angular/core';
 | |
| 
 | |
| @Component({
 | |
|  selector: 'my-app',
 | |
|  template: 'Welcome to Angular'
 | |
| })
 | |
| export class AppComponent {
 | |
|   constructor(logger: Logger) {
 | |
|     logger.log('Let the fun begin!');
 | |
|   }
 | |
| }
 | |
| 
 | |
| import { NgModule }      from '@angular/core';
 | |
| import { BrowserModule } from '@angular/platform-browser';
 | |
| @NgModule({
 | |
|   imports:      [ BrowserModule ],
 | |
|   providers:    [ Logger ],
 | |
|   declarations: [ AppComponent ],
 | |
|   exports:      [ AppComponent ],
 | |
|   bootstrap:    [ AppComponent ]
 | |
| })
 | |
| export class AppModule { }
 | |
| 
 | |
| import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
 | |
| 
 | |
| 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[app/sales-tax.component.ts]" value="import { Component }       from '@angular/core';
 | |
| 
 | |
| import { SalesTaxService } from './sales-tax.service';
 | |
| import { TaxRateService }  from './tax-rate.service';
 | |
| 
 | |
| @Component({
 | |
|   selector:    'sales-tax',
 | |
|   template: `
 | |
|     <h2>Sales Tax Calculator</h2>
 | |
|     Amount: <input #amountBox (change)="0">
 | |
| 
 | |
|     <div *ngIf="amountBox.value">
 | |
|     The sales tax is
 | |
|      {{ getTax(amountBox.value) | currency:'USD':true:'1.2-2' }}
 | |
|     </div>
 | |
|   `,
 | |
|   providers: [SalesTaxService, TaxRateService]
 | |
| })
 | |
| export class SalesTaxComponent {
 | |
|   constructor(private salesTaxService: SalesTaxService) { }
 | |
| 
 | |
|   getTax(value: string | number) {
 | |
|     return this.salesTaxService.getVAT(value);
 | |
|   }
 | |
| }
 | |
| 
 | |
| 
 | |
| /*
 | |
| 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/sales-tax.service.ts]" value="import { Injectable } from '@angular/core';
 | |
| 
 | |
| import { TaxRateService } from './tax-rate.service';
 | |
| 
 | |
| @Injectable()
 | |
| export class SalesTaxService {
 | |
|   constructor(private rateService: TaxRateService) { }
 | |
| 
 | |
|   getVAT(value: string | number) {
 | |
|     let amount = (typeof value === 'string') ?
 | |
|       parseFloat(value) : value;
 | |
|     return (amount || 0) * this.rateService.getRate('VAT');
 | |
|   }
 | |
| }
 | |
| 
 | |
| 
 | |
| /*
 | |
| 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/tax-rate.service.ts]" value="import { Injectable } from '@angular/core';
 | |
| 
 | |
| @Injectable()
 | |
| export class TaxRateService {
 | |
|   getRate(rateName: string) { return 0.10; } // 10% everywhere
 | |
| }
 | |
| 
 | |
| 
 | |
| /*
 | |
| 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="import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
 | |
| import { AppModule } from './app/app.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[app/hero-detail.component.html]" value="<hr>
 | |
| <h4>{{hero.name}} Detail</h4>
 | |
| <div>Id: {{hero.id}}</div>
 | |
| <div>Name:
 | |
|   <input [(ngModel)]="hero.name">
 | |
| </div>
 | |
| <div>Power:<input [(ngModel)]="hero.power"></div>
 | |
| 
 | |
| 
 | |
| <!-- 
 | |
| 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-list.component.html]" value="<h2>Hero List</h2>
 | |
| 
 | |
| <p><i>Pick a hero from the list</i></p>
 | |
| <ul>
 | |
|   <li *ngFor="let hero of heroes" (click)="selectHero(hero)">
 | |
|     {{hero.name}}
 | |
|   </li>
 | |
| </ul>
 | |
| 
 | |
| <hero-detail *ngIf="selectedHero" [hero]="selectedHero"></hero-detail>
 | |
| 
 | |
| 
 | |
| <!-- 
 | |
| 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>
 | |
|     <title>Architecture of Angular</title>
 | |
|     <meta charset="UTF-8">
 | |
|     <meta name="viewport" content="width=device-width, initial-scale=1">
 | |
|     <script>document.write('<base href="' + document.location + '" />');</script>
 | |
|     <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="private" value="true"><input type="hidden" name="description" value="Angular Example - Intro to Angular"></form><script>document.getElementById("mainForm").submit();</script></body></html> |