Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import {
  2. Component,
  3. Template,
  4. For,
  5. If,
  6. bootstrap,
  7. Parent,
  8. DynamicComponent} from 'angular2/angular2';
  9. import MovieFactory from './services/movieFactory';
  10.  
  11.  
  12. @Component({
  13. selector: 'hello',
  14. services: [MovieFactory]
  15. })
  16. @Template({
  17. directives: [Tabs, For],
  18. inline: `
  19. <tabs>
  20. </tabs>
  21. `,
  22. })
  23. export class Hello {
  24. constructor(movieFactory: MovieFactory) {
  25. this.factory = movieFactory;
  26. this.list = [];
  27. this.factory.getMovies()
  28. .then(mov => {
  29. mov.movies.forEach(movie => {
  30. movie.active = this.list.length === 0;
  31. this.list.push({
  32. title: movie.title, desc: movie.description, active: movie.active
  33. });
  34. });
  35. });
  36. }
  37. }
  38.  
  39.  
  40. @Component({
  41. selector: 'tabs',
  42. services: [],
  43. })
  44. @Template({
  45. inline: `
  46. <ul>
  47. <li *for="#tab of tabs; #i = index" (click)="selectTab(tab, i)">
  48. {{tab.title}}
  49. </li>
  50. </ul>
  51. <div *if="tabs[index]">
  52. {{tabs[index].desc}}
  53. </div>
  54. `,
  55. directives: [For, If]
  56. })
  57. export class Tabs {
  58. constructor(@Parent() hello: Hello) {
  59. this.tabs = [];
  60. this.index = 0;
  61. setTimeout(() => { //This is crappy I know
  62. if (hello.list.length) {
  63. hello.list.forEach(t => {
  64. this.tabs.push(t);
  65. });
  66. }
  67. }, 10);
  68. }
  69.  
  70. selectTab(tab, i) {
  71. this.index = i;
  72. }
  73. }
  74.  
  75. export function main() {
  76. return bootstrap(Hello);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement