Last active
September 17, 2018 14:57
-
-
Save leochen0818/22e0c9649f3ce4976322a2dd9b975c6e to your computer and use it in GitHub Desktop.
Angular Style guide nagetive sample from style 01-01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* avoid */ | |
import { Component, NgModule, OnInit } from '@angular/core'; | |
import { BrowserModule } from '@angular/platform-browser'; | |
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | |
class Hero { | |
id: number; | |
name: string; | |
} | |
@Component({ | |
selector: 'my-app', | |
template: ` | |
<h1>{{title}}</h1> | |
<pre>{{heroes | json}}</pre> | |
`, | |
styleUrls: ['app/app.component.css'] | |
}) | |
class AppComponent implements OnInit { | |
title = 'Tour of Heroes'; | |
heroes: Hero[] = []; | |
ngOnInit() { | |
getHeroes().then(heroes => (this.heroes = heroes)); | |
} | |
} | |
@NgModule({ | |
imports: [BrowserModule], | |
declarations: [AppComponent], | |
exports: [AppComponent], | |
bootstrap: [AppComponent] | |
}) | |
export class AppModule {} | |
platformBrowserDynamic().bootstrapModule(AppModule); | |
const HEROES: Hero[] = [ | |
{ id: 1, name: 'Bombasto' }, | |
{ id: 2, name: 'Tornado' }, | |
{ id: 3, name: 'Magneta' } | |
]; | |
function getHeroes(): Promise<Hero[]> { | |
return Promise.resolve(HEROES); // TODO: get hero data from the server; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment