Angular2 - Try angular.io's tutorial

2016/5/281 min read
bookmark this
Responsive image

Start doing angular2's tutorial

import { Component } from '@angular/core';

export class Name {
	id: number;
	first: string;
}

const NAMES: Name[] = [
  { id: 11, first: 'Mr. Nice' },
  { id: 12, first: 'Narco' },
  { id: 13, first: 'Bombasto' },
  { id: 14, first: 'Celeritas' },
  { id: 15, first: 'Magneta' },
  { id: 16, first: 'RubberMan' },
  { id: 17, first: 'Dynama' },
  { id: 18, first: 'Dr IQ' },
  { id: 19, first: 'Magma' },
  { id: 20, first: 'Tornado' }
];

@Component({
  selector: 'my-app',
  template: `
{{title}}
  • {{n.id}}: {{n.first}}
{{selectedName.id}}
  `,
  styles: [`
	  h6 {
	  	font-size: small;
	  }
	  ul li.selected {
	  	font-size: large;
	  }
  `]
})
export class AppComponent {
  title = 'Awesome';
  names = NAMES;

  onSelect(name: Name) {
  	this.selectedName = name;
  	console.info(name);
  }
}