Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. import {Component, ChangeDetectionStrategy} from "angular2/core";
  2. import {MyFilterPipe} from "./myfilter";
  3.  
  4. @Component({
  5. selector: "Home",
  6. template: `
  7. <div class="container-fluid">
  8. <div class="row">
  9. <div class="col-sm-3 col-sm-offset-2">
  10. <h2>A list of teams: </h2>
  11. <ul>
  12. <li *ngFor="#teamName of teams | myfilter:fTeam">{{teamName}}</li>
  13. </ul>
  14. </div>
  15. </div>
  16. <div class="row">
  17. <form class="form-horizontal col-sm-12">
  18. <div class="form-group">
  19. <label for="fTeam" class="control-label col-sm-2">Filter teams: </label>
  20.  
  21. <div class="col-sm-2">
  22. <input [(ngModel)]="fTeam" class="form-control" id="fTeam" type="text"/>
  23. </div>
  24. </div>
  25.  
  26. <div class="form-group">
  27. <label for="newTeam" class="control-label col-sm-2">Add team: </label>
  28.  
  29. <div class="col-sm-2">
  30. <input [(ngModel)]="newTeam" class="form-control" id="newTeam" type="text"/>
  31. </div>
  32.  
  33. <div class="col-sm-2">
  34. <button (click)="addTeam(newTeam)" id="addBtn" class="btn btn-small">
  35. Add team
  36. </button>
  37. </div>
  38. </div>
  39. <div class="form-group">
  40. <label for="deleteTeam" class="control-label col-sm-2">
  41. Remove a team:
  42. </label>
  43.  
  44. <div class="col-sm-2">
  45. <select class="form-control"
  46. [(ngModel)]="team"
  47. ngControl="deleteTeam"
  48. #deleteTeam="ngForm" >
  49. <option *ngFor="#t of teams" [value]="t">{{t}}</option>
  50. </select>
  51.  
  52. </div>
  53. <button (click)="removeTeam(team)" id="delBtn" class="btn btn-small">
  54. Delete team
  55. </button>
  56. </div>
  57.  
  58. <div class="form-group">
  59. <div class="col-sm-1 col-sm-offset-2">
  60. <!-- Challenge: restore the dropped teams, set the button here
  61. Add the usual classes to the button
  62. -->
  63.  
  64. </div>
  65. </div>
  66. </form>
  67. </div>
  68. </div>
  69. `,
  70. styles: [`
  71. .selected {
  72. background-color: #CFD8DC !important;
  73. color: white;
  74. }
  75. `],
  76. directives: [],
  77. pipes: [MyFilterPipe],
  78. changeDetection: ChangeDetectionStrategy.CheckAlways
  79. })
  80.  
  81. export class EventComponent {
  82. public teams:string[] = ['Mets', 'Yankees', 'Red Sox', 'Phillies', 'Blue Jays',
  83. 'Braves', 'Orioles', 'Marlins', 'Rays', 'Nationals'];
  84. public fTeam:string = "";
  85.  
  86. addTeam(team:string) {
  87. this.teams.push(team);
  88. }
  89.  
  90. removeTeam(team:string) {
  91. var index = this.teams.indexOf(team);
  92. this.teams.splice(index, 1);
  93. }
  94.  
  95. //onSelect(link:Link) {
  96. // this.selectedLink = link;
  97. //}
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement