Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import {Component} from 'angular2/core';
  2.  
  3. interface Hero {
  4. id: number;
  5. name: string;
  6. }
  7.  
  8.  
  9. @Component({
  10. selector: 'my-app',
  11. template:`
  12. <h1>{{title}}</h1>
  13. <h2>{{selectedHero.name}} details!</h2>
  14. <div><label>id: </label>{{selectedHero.id}}</div>
  15. <div>
  16. <label>name: </label>
  17. <div><input [(ngModel)]="selectedHero.name" placeholder="name"></div>
  18. </div>
  19. <h2>My Heroes</h2>
  20. <ul class="heroes">
  21. <li *ngFor="#hero of heroes" (click)="onSelect(hero)">
  22. <span class="badge">{{hero.id}}</span> {{hero.name}}
  23. </li>
  24. </ul>
  25. `,
  26. styles:[`
  27. .selected {
  28. backgroun d-color: #CFD8DC !important;
  29. color: white;
  30. }
  31. .heroes {
  32. margin: 0 0 2em 0;
  33. list-style-type: none;
  34. padding: 0;
  35. width: 10em;
  36. }
  37. .heroes li {
  38. cursor: pointer;
  39. position: relative;
  40. left: 0;
  41. background-color: #EEE;
  42. margin: .5em;
  43. padding: .3em 0em;
  44. height: 1.6em;
  45. border-radius: 4px;
  46. }
  47. .heroes li.selected:hover {
  48. color: white;
  49. }
  50. .heroes li:hover {
  51. color: #607D8B;
  52. background-color: #EEE;
  53. left: .1em;
  54. }
  55. .heroes .text {
  56. position: relative;
  57. top: -3px;
  58. }
  59. .heroes .badge {
  60. display: inline-block;
  61. font-size: small;
  62. color: white;
  63. padding: 0.8em 0.7em 0em 0.7em;
  64. background-color: #607D8B;
  65. line-height: 1em;
  66. position: relative;
  67. left: -1px;
  68. top: -4px;
  69. height: 1.8em;
  70. margin-right: .8em;
  71. border-radius: 4px 0px 0px 4px;
  72. }
  73. `]
  74.  
  75.  
  76. })
  77. export class AppComponent {
  78. public title = 'Tour of Heroes';
  79. public heroes = HEROES;
  80. public selectedHero: Hero;
  81.  
  82. onSelect(hero: Hero) { this.selectedHero = hero; }
  83. }
  84.  
  85. var HEROES: Hero[] = [
  86. { "id": 11, "name": "Mr. Nice" },
  87. { "id": 12, "name": "Narco" },
  88. { "id": 13, "name": "Bombasto" },
  89. { "id": 14, "name": "Celeritas" },
  90. { "id": 15, "name": "Magneta" },
  91. { "id": 16, "name": "RubberMan" },
  92. { "id": 17, "name": "Dynama" },
  93. { "id": 18, "name": "Dr IQ" },
  94. { "id": 19, "name": "Magma" },
  95. { "id": 20, "name": "Tornado" }
  96. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement