Skip to content

Instantly share code, notes, and snippets.

@leochen0818
Last active September 17, 2018 14:57
Show Gist options
  • Save leochen0818/22e0c9649f3ce4976322a2dd9b975c6e to your computer and use it in GitHub Desktop.
Save leochen0818/22e0c9649f3ce4976322a2dd9b975c6e to your computer and use it in GitHub Desktop.
Angular Style guide nagetive sample from style 01-01
/* 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